现在的位置: 首页 > 综合 > 正文

tcl/tk参考——变量和过程unset

2013年12月20日 ⁄ 综合 ⁄ 共 536字 ⁄ 字号 评论关闭

.

.

名称

unset - 删除变量

语法

unset ?-nocomplain? ?--? ?name name name ...?

描述

这个命令删除一个或多个变量,每个name都是一个变量名,指定的方式和set命令相同,如果name已用一个数组的元素那么这个元素将被删除掉,如果name由是一个没有索引的数组名那么这个数组将被删除掉,unset命令返回一个空字符串。如果指定了-nocomplain就禁止错误输出,可选项--代表可选项结束,如果需要删除的变量名以-开头就需要指定--可选项。如果产生错误,在产生错误的变量之后的变量都不会被删除。当变量不存在、引用的数组元素是一个标量或者引用一个不存在的名字空间都会产生错误。

示例

创建包含一些数字索引的数组,数组元素的内容为索引的平方,然后把非素数索引的数组元素删除:

array set squares {
    1 1    6 36
    2 4    7 49
    3 9    8 64
    4 16   9 81
    5 25  10 100
}

puts "The squares are:"
parray squares

unset squares(1) squares(4) squares(6)
unset squares(8) squares(9) squares(10)

puts "The prime squares are:"
parray squares

 

抱歉!评论已关闭.