Tcl placing a value of a variable as the name a the variable

后端 未结 2 643
情书的邮戳
情书的邮戳 2021-01-23 00:04

I\'m having some issues with Tcl. I have a variable that has a string in it. Butt now I want this string to be the name of a next variable.

I have found some similar que

2条回答
  •  礼貌的吻别
    2021-01-23 00:33

    The correct solution is to use $name as first parameter to set

    set name "foo"
    set $name "bar"
    puts $foo ;# -> bar
    

    But if you try to use $name it will yield foo, not bar (Which is what you do in your code according to the comments. I don't know why you need a variable whose name you don't know, but anyway:

    puts [set $name] ;# -> bar
    

    will give you the correct thing. The same works with objects:

    set topcell [[set $name] topcell]
    

    So I have to ask you: what do you want to do with the dynamic named variable then?

提交回复
热议问题