Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove items from Dictionary

Status
Not open for further replies.

bellecombe

Instructor
Oct 15, 2003
7
0
0
IT
Hi
I need to remove some entries from dict, based on pattern i.e.:
[pre]set keyValueMap [dict create "WidgetTEXT" "T" "WidgetPASSWORD" "P" "defValuesDEFAULTS" "DEFAULT" "defValuesRDB" "R"]
set keyValueMap [dict remove $keyValueMap [join [dict keys $keyValueMap "Widget*"]]]

[/pre]
Although [tt][join [dict keys $keyValueMap "Widget*"][/tt] returns [tt]WidgetTEXT WidgetPASSWORD[/tt], this doesn't works;
instead when hard coded: [tt]set keyValueMap [dict remove $keyValueMap WidgetTEXT WidgetPASSWORD][/tt] works.
What is my mistake?

best regards
 
This is taken as a whole string
Code:
join [dict keys $keyValueMap "Widget*"]

It is like issuing
Code:
set keyValueMap [dict remove $keyValueMap "WidgetTEXT WidgetPASSWORD"]

The string needs to be split into its individual components using {*}
Code:
set keyValueMap [dict remove $keyValueMap {*}[join [dict keys $keyValueMap "Widget*"]]]
 
Tanks xwb, I wasn't aware of the expansion operator.
best regards
 
Actually, come to think of it, you don't really need the join. This will also work

Code:
set keyValueMap [dict remove $keyValueMap {*}[dict keys $keyValueMap "Widget*"]]
 
Thanks, I already tried it without the join and saw that it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top