Visible to Intel only — GUID: mwh1410471029804
Ixiasoft
Visible to Intel only — GUID: mwh1410471029804
Ixiasoft
3.9.6. Arrays
To set an element with an index of Mon to a value of Monday in an array called days, use the following command:
set days(Mon) Monday
The array set command requires a list of index/value pairs. This example sets the array called days:
array set days { Sun Sunday Mon Monday Tue Tuesday\
Wed Wednesday Thu Thursday Fri Friday Sat Saturday }
set day_abbreviation Mon
puts $days($day_abbreviation)
Use the array names command to get a list of all the indexes in a particular array. The index values are not returned in any specified order. The following example is one way to iterate over all the values in an array.
foreach day [array names days] {
puts "The abbreviation $day corresponds to the day name $days($day)"
}
Arrays are a very flexible way of storing information in a Tcl script and are a good way to build complex data structures.