Dictionary 从由变量值构造的变量名获取字典值

Dictionary 从由变量值构造的变量名获取字典值,dictionary,tcl,concat,Dictionary,Tcl,Concat,以下是一些格言: set d0 [dict create key1 value1] set d1 [dict create key1 value1] 我现在需要为每个字典获取value1,比如在循环中: for {set i 0} {$i < 2} {incr i} { dict get $d$i } 对于{set i 0}{$i

以下是一些格言:

set d0 [dict create key1 value1]
set d1 [dict create key1 value1]
我现在需要为每个字典获取
value1
,比如在循环中:

for {set i 0} {$i < 2} {incr i} {
    dict get $d$i
}
对于{set i 0}{$i<2}{incr i}{
dict得到$d$i
}
我的问题在于循环的第二行,其中我无法连接并正确获取字典值,此结构需要一个
$
来调用字典名称,与
dict append
命令相反,我尝试使用
{}
[]
concat
join
无效,当然,我遗漏了一些东西或误解了编写Tcl的方式。

您的直接解决方案是:

dict get [set d$i] ...
因为
$
在很大程度上是单个参数
set
命令的限制性语法糖

但是把词典放在一个数组中。

set d(0) [dict create key1 value1]
set d(1) [dict create key1 value1]
for {set i 0} {$i < 2} {incr i} {
    dict get $d($i) ...
}
设置d(0)[dict create key1 value1]
集合d(1)[dict create key1 value1]
对于{set i 0}{$i<2}{incr i}{
dict得到$d($i)。。。
}
它的语法要好得多

您的即时解决方案是:

dict get [set d$i] ...
因为
$
在很大程度上是单个参数
set
命令的限制性语法糖

但是把词典放在一个数组中。

set d(0) [dict create key1 value1]
set d(1) [dict create key1 value1]
for {set i 0} {$i < 2} {incr i} {
    dict get $d($i) ...
}
设置d(0)[dict create key1 value1]
集合d(1)[dict create key1 value1]
对于{set i 0}{$i<2}{incr i}{
dict得到$d($i)。。。
}
它的语法要好得多