开发者

keylset bug in Tcl 8.4 and 8.5?

开发者 https://www.devze.com 2023-03-10 10:44 出处:网络
Consider the following simple exercise: 开发者_如何学运维package require Tclx keylset myArray \"v1.5\" \"ready\"

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

  1. This seems to be an error in keylset, I have confirmed this behavior on both 8.4 and 8.5
  2. 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

0

精彩评论

暂无评论...
验证码 换一张
取 消