November 1999
Intermediate to advanced
832 pages
19h 28m
English
The index of an array is delimited by parentheses. The index can have any string value, and it can be the result of variable or command substitution. Array elements are defined with set:
set arr(index) value
The value of an array element is obtained with $ substitution:
set foo $arr(index)
Example 8-1 uses the loop variable value $i as an array index. It sets arr(x) to the product of 1 * 2 * ... * x:
set arr(0) 1
for {set i 1} {$i <= 10} {incr i} {
set arr($i) [expr {$i * $arr([expr $i-1])}]
}
|
An array index can be any string, like orange, 5, 3.1415, or foo,bar. The examples in this chapter, and in this book, often use indices that are pretty complex strings to create flexible data ...
Read now
Unlock full access