使用密钥集在密钥名称中设置唯一字符
问题描述:
我试图设置密钥列表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]"
输出:从运行keylkeys data
仅接收2键
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
的通知。
找不到任何相关文档。也许我没有正确使用它?
答
键控列表使用.
作为结构化键分隔符; .
之后的部分是子密钥。如果我们打印的整体键列表,我们可以看到事情已经解释:
% 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