From: Uwe Klein on
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
Thanks to all of you. All the solutions worked for me :)