Posted to tcl by aspect at Fri Mar 14 13:21:19 GMT 2014view pretty

set key {/foo/[bar]/baz}
# equivalent:
# set key "/foo\[bar\]/baz"
# or even:
# set key /foo\[bar\]/baz

set globKey {/foo/\[bar\]/baz}
# equivalent:
# set globKey "/foo/\\\[bar\\\]/baz"
# set globKey /foo/\\\[bar\\\]/baz

dict set d ignore me
dict set d $key "Hello, world"
dict set d "a${key}b" "Hello again"

puts "key = $key"
puts "globKey = $globKey"
puts "d = $d"

puts "\[dict get \$d \$key\] = [dict get $d $key]"

puts "\[dict filter \$d key \$globKey\] = [dict filter $d key $globKey]"

# these two are the same, because you can elide "" for a single word:
puts "\[dict filter \$d key *\$globKey*\] = [dict filter $d key *$globKey*]"
puts "\[dict filter \$d key \"*\$globKey*\"\] = [dict filter $d key "*$globKey*"]"