Ashot
Ashot

Reputation: 10959

TCL: How to create and use variable with names containing curly braces?

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?

Upvotes: 1

Views: 862

Answers (1)

Johannes Kuhn
Johannes Kuhn

Reputation: 15163

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

Upvotes: 5

Related Questions