1

Some variable names in my program are constructed from inputs of user so they may contain any symbols. Some symbols are treated as special by interpreter e.g. $,#, .... The problems concerning that symbols were solved by adding open brace on the beginning of constructed variable name and close brace at the end of it. But now another problem arises when the name of variable contains curly closing brace.

set "a{}" text

puts $a{}
puts ${a{}}

None of tow puts work here. How can I print the value of variable a{} and is there any known method for dealing with special symbols in TCL?

2
  • @JohannesKuhn, post that as an answer Aug 9, 2013 at 18:24
  • 2
    Note that if you're doing this a lot, it probably means you should use the “strange character”-containing name as the name of an array element. set ary(a{}) text; puts $ary(a{}) Aug 10, 2013 at 8:20

1 Answer 1

5

From the manual:

Note that variables may contain character sequences other than those listed above, but in that case other mechanisms must be used to access them (e.g., via the set command's single-argument form).

Use set

puts [set "a{}"]

the $ way is restricted, set is not

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.