Consider the following simple exercise:
开发者_如何学运维package require Tclx
keylset myArray "v1.5" "ready"
puts $myArray
The expected output:
{v1.5 ready}
The actual output:
{v1 {{5 ready}}}
My questions are
- This seems to be an error in keylset, I have confirmed this behavior on both 8.4 and 8.5
- How do I get around it? I have tried several ways to quote the key to no avail.
It's not a bug, it's a feature. :) Dot is a hierarchical key separator in keyed list.
See the example for explanation:
keylset myArray {v1.5} "ready" {v1.6} "empty"
puts $myArray ;# ==> {v1 {{5 ready} {6 empty}}}
puts [keylget myArray v1] ;# ==> {5 ready} {6 empty}
puts [keylget myArray v1.5] ;# ==> ready
puts [keylget myArray v1.6] ;# ==> empty
keylset is a Tclx command. I would really recommend you to take a look to the dict command from Tcl 8.5
精彩评论