Prev: How to change or set a string variable in Tcl/tk to a specificcolor to be displayed via tk_messageBox
Next: TclApp / TclKit & auto_execok
From: Uwe Klein on 24 Jun 2010 09:39 ashu wrote: > Thanks Alex. > > The array mentioned in the previous post "mylist" may contain various > types of keys. Some of them may contain "[]", while some may not. > Consequently, at the time of accessing the keys using array names > [pattern]/array get [pattern], I may not know whether the $i2 contains > "[]". > > Is there any other way of storing elements like "i2" (containing > metacharacters) in the associative array so that the array names/get > works correctly? You are asking the wrong question ;-) in [array names $arr $patt] or [array get $arr $patt] $patt is evaluated as a glob style pattern! there is no limitation to what can be used for an array key. try: proc escape4glob patt { set escaped [ string map [list \{ \\\{ \} \\\{ \[ \\\[ \] \\\] * \\*] $patt ] } set testpatt [ escape4glob $i1 ],[ escape4glob $i2 ],* [array get $arr $testpatt] uwe
From: ashu on 25 Jun 2010 00:25
Thanks to all of you. All the solutions worked for me :) |