Chinaunix首页 | 论坛 | 博客
  • 博客访问: 182611
  • 博文数量: 42
  • 博客积分: 2235
  • 博客等级: 大尉
  • 技术积分: 460
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-15 20:17
文章分类

全部博文(42)

文章存档

2012年(1)

2011年(7)

2010年(33)

2009年(1)

我的朋友

分类:

2010-02-09 20:59:44

array ----操作数组变量

语法:
array option arrayName ?arg arg ...?

该命令对于arrayName进行一系列操作。除非下文指定单独命令,arrayName必须为一个存在的数组变量。选项决定命令执行的方式。合法的选项为:

array anymore arrayName searchId
  如果在查找中仍然存在更多的元素,则返回1
 
array donesearch arrayName searchId
  根据searchId来决定终止数组查找并销毁所有状态

array exists arrayName
  如果arrayName存在则返回1,否则为0

array get arrayName ?pattern?
  返回arrayName的索引和值

array names arrayName ?mode? ?pattern?
  返回在arrayName中和pattern匹配的一系列的数组名字。mode为-exact,-glob,-regexp

array nextelement arrayName searchId
  返回arrayName的下一个元素的名字,或者当arrayName中的所有元素已经在查找中返回空字符串。

array set arrayName list
  初始化list 为名为arrayName的数组

array size arrayName
  返回arrayName的元素数值

array startsearch arrayName
  由arrayName按元素顺序进行查找并返回令牌

array statistics arrayName
  返回表示arrayName的hash表的分布数据

array unset arrayName ?pattern?
  销毁数组arrayName
 
array set colorcount {
    red   1
    green 5
    blue  4
    white 9
}

foreach {color count} [array get colorcount] {
   puts "Color: $color Count: $count"
}
 => Color: blue Count: 4
    Color: white Count: 9
    Color: green Count: 5
    Color: red Count: 1

foreach color [array names colorcount] {
   puts "Color: $color Count: $colorcount($color)"
}
 => Color: blue Count: 4
    Color: white Count: 9
    Color: green Count: 5
    Color: red Count: 1

foreach color [lsort [array names colorcount]] {
    puts "Color: $color Count: $colorcount($color)"
}
 => Color: blue Count: 4
    Color: green Count: 5
    Color: red Count: 1
    Color: white Count: 9

array statistics colorcount
 => 4 entries in table, 4 buckets
    number of buckets with 0 entries: 1
    number of buckets with 1 entries: 2
    number of buckets with 2 entries: 1
    number of buckets with 3 entries: 0
    number of buckets with 4 entries: 0
    number of buckets with 5 entries: 0
    number of buckets with 6 entries: 0
    number of buckets with 7 entries: 0
    number of buckets with 8 entries: 0
    number of buckets with 9 entries: 0
    number of buckets with 10 or more entries: 0
    average search distance for entry: 1.2  
阅读(1520) | 评论(0) | 转发(0) |
0

上一篇:join命令

下一篇:makefile解析

给主人留下些什么吧!~~