如何在tcl中设置变量
我看到有人这样设置变量:
set selectRoom(1,deflt) 1
这个selectRoom(1,deflt)
是什么意思?这是如何运作的?
I saw someone set a variable in this way:
set selectRoom(1,deflt) 1
what does this selectRoom(1,deflt)
means? how this works?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
selectRoom
是一个数组,1,deflt
是索引。要查看数组中设置的内容,可以使用
parray
或array get
命令。selectRoom
is an array and1,deflt
is the index.To see what is set in the array, you can use
parray
orarray get
command.正如之前所说,
selectRoom
是一个数组,但我只想扩展这个答案。您可能会认为索引
1,deflt
表明这是一个二维数组。事实上并非如此; Tcl 不支持多维数组。逗号符号只是 Tcl 程序员用来模拟多维数组的约定。逗号是字符串的一部分,而不是 andy 类型的特殊分隔符。在 Tcl 中,数组有点像其他语言中的哈希映射。索引始终是一个字符串(因为Tcl 中的所有内容都是字符串)。这还有另一个含义:它们没有排序,因此在迭代它们时必须小心。
As was said before,
selectRoom
is an array, but I would just like to expand on that answer.You might be tempted to think that the index
1,deflt
suggests that this is a 2 dimensional array. In fact it isn't; Tcl does not support multidimensional arrays. The comma notation is just a convention that Tcl programmers use to simulate multidimensional arrays. The comma is part of the string, not andy kind of special delimiter.In Tcl, arrays are a bit like hash maps in other languages. The index is always a string (because everything is a string in Tcl). This has another implication: they are not ordered, so you have to be careful when you are iterating over them.