我们假设filevalue_ $ thefile是一个包含列表的数组
foreach element [array names thefilevalue_$thefile] {
puts "[lindex $thefilevalue_[subst $thefile]($element) 0]"
}
Run Code Online (Sandbox Code Playgroud)
但它返回:
can't read "thefilevalue_": no such variable
我在tcl 8.4,我不能升级它.
我该怎么办呢?
谢谢
使用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]
}
Run Code Online (Sandbox Code Playgroud)
这为我输出(Tcl 8.0.5,我也无法升级):
orange
green
Run Code Online (Sandbox Code Playgroud)