Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TCL question

Status
Not open for further replies.

ghou

Technical User
Feb 17, 2009
1
US
Hello,
I have a simple tcl question.
I have a variable name which has the value of another variable in it. How do I reference the value of this variable?

eg
set a 3
set b_$a 5

How do I reference the value of b_$a?

If I use $b_$a, it does not work. I have tried other things like using ${b_$a} etc, but to no avail.

Any help is appreciated.
 
It depends on in what context you want to refer to it. Say you want to set another variable equal to the contents of "b_3", that is, "b_$a". You can use set as in:
Code:
set newvar [set b_$a]

Alternatively, you can use delayed substitution, append, and subst:
Code:
set c {$b}
append c -$a
subst $c

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top