networktestinggenius.tk
Your networking tutor
Exclusive networking testing notes
Learn Networking & Testing topics

Arrays
Tcl arrays can be created with the set or array set commands.
set names(1) Thiru
set names(2) Bhuvana
set names(3) Selvi
set names(4) Madhavan
set names(5) Raja
set names(6) Ananth
puts [array exists names]
puts [array size names]
puts $names(1)
puts $names(2)
puts $names(6)
array set days {
1 Monday
2 Tuesday
3 Wednesday
4 Thursday
5 Friday
6 Saturday
7 Sunday
}
set n [array size days]
puts $days(1)
puts "array has $n elements"
array exists arrayName Returns 1 if arrayName is an array variable. Returns 0 if arrayName is a scalar variable, proc, or does not exist.
array names arrayName ?pattern Returns a list of the indices for the associative array arrayName. If pattern is supplied, only those indices that match pattern are returned. The match is done using the globbing technique from string match.
array size arrayName Returns the number of elements in array arrayName.
array get arrayName Returns a list in which each odd member of the list (1, 3, 5, etc) is an index into the associative array. The list element following a name is the value of that array member.
array set arrayName dataList Converts a list into an associative array. DataList is a list in the format of that returned by array get. Each odd member of the list (1, 3, 5, etc) is an index into the associative array, and the list element following that is the value of that array member.
Iteration of Associative Array
set candidate(Name) "Thiru"
set candidate(Age) 25
foreach index [array names candidate] {
puts "candidate($index): $candidate($index)"
}