使用keylset在键名中设置唯一字符

时间:2014-01-30 09:53:51

标签: tcl

我正在尝试使用keylset设置键控列表,但显然它不接受键名称中的点(.)等唯一字符。 例如,以下代码(Tcl 8.5):

puts "conditions=$conditions"
if {[llength $conditions] > 0} {
    foreach {name value} $conditions {
        puts "keylset data \"$name\" \"$value\""
        keylset data "$name" "$value"
    }
}
puts "keylkeys data = [keylkeys data]"

输出:

conditions=abc.de hello bar.world Stack bar.dog Exchange
keylset data "abc.de" "hello"
keylset data "bar.world" "Stack"
keylset data "bar.dog" "Exchange"
keylkeys data = abc bar

请注意,只有2个密钥从运行keylkeys data收到 找不到任何相关文档。也许我没有正确使用它?

1 个答案:

答案 0 :(得分:1)

键控列表使用.作为结构化键分隔符; .之后的部分是子键。如果我们打印整体键控列表,我们可以看到事情的解释:

% puts $data
{abc {{de hello}}} {bar {{world Stack} {dog Exchange}}}

如果您需要任意密钥,请改用字典(可从Tcl 8.5获得)。

dict set example abc.de "hello"
dict set example bar.world "Stack"
dict set example bar.dog "Exchange"
puts $example
#--> abc.de hello bar.world Stack bar.dog Exchange
puts [dict keys $example]
#--> abc.de bar.world bar.dog