为什么TCL脚本中的数组大小没有由数组大小<array_name>正确给出? [英] Why is the size of array in TCL script is not given properly by array size <array_name>

查看:18
本文介绍了为什么TCL脚本中的数组大小没有由数组大小<array_name>正确给出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我有一个包含 4 个元素的数组,但它打印的值为 11,所以大小如何变为 11 而不是 4

Here I am having a array of 4 elements but the it prints the value as 11 so how does the size has become 11 instead of 4

array set ipname {UART TEST SPI I2C}
set bsize [array size ipname];
puts "$bsize"

推荐答案

array set(在您的情况下只生成 两个 元素!)不会删除任何现有的数组的内容,之前必须有 9 到 11 个元素.如果我在一个空的 tclsh 中运行你的代码,它会打印 2.如果我接着使用 parray,它会告诉我它做了什么:

The array set (which only makes two elements in your case!) does not remove any existing contents of the array, which must have had between 9 and 11 elements in it previously. If I run your code in a bare tclsh, it prints 2. If I then follow up with parray, it tells me what it did:

% parray ipname
ipname(SPI)  = I2C
ipname(UART) = TEST

这篇关于为什么TCL脚本中的数组大小没有由数组大小<array_name>正确给出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆