0

thefilevalue_$thefileがリストを含む配列であると仮定しましょう

foreach element [array names thefilevalue_$thefile] {
    puts "[lindex $thefilevalue_[subst $thefile]($element) 0]"
}

しかし、それは戻ります:

can't read "thefilevalue_": no such variable

私はtcl8.4を使用していますが、アップグレードしません。

どうすれば修正できますか?

ありがとう

4

1 に答える 1

6

括弧を使用setしてエスケープします。

array set thefilevalue_test {reds {orange red purple} blues {green blue purple}}
set thefile test
foreach element [array names thefilevalue_$thefile] {
    puts [lindex [set thefilevalue_$thefile\($element\)] 0]
}

これは私のために出力します(Tcl 8.0.5、そして私もアップグレードできません):

orange
green
于 2012-08-10T14:24:38.807 に答える