Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
array set myarray {}
for {set x 0 ; set c [expr $x + 1]} {$x <100} {incr x ; incr c} {
set myarray($x,$c) [expr int(1 + rand() * $c)]
}
[\code]
Which creates an indiced array that can be handled as
a two dimensional data structure.
Too fully emulate a C type 2d array's indexing scheme is
simple too.
[code]
for {set x 0} {$x < 100} {incr x} {
for {set c 0} {$c < 10} {incr c} {
set myarray($x,$c) [expr int(1 + rand() * $x + $c)]
}
}
HTH
proc retrieveInd {arrname ind {indopt "*"}} {
upvar #0 $arrname local
if {"$indopt" == "*"} {
puts "Printing all indexes for array index $ind"
foreach a [array name local $ind,$indopt] {
regexp "(\[0-9\]+),(\[0-9\]+)" $a a1 a2 a3
puts "Index $a2, element $a3 = $local($a)"
}
} else {
foreach a [array name local $ind,$indopt] {
regexp "(\[0-9\]+),(\[0-9\]+)" $a a1 a2 a3
puts "$a2,$a3 = $local($a)"
}
}
return 0
}
[\code]
Sample run
retrieveInd myarray 12 3
12,3 = 10
0
or:
retrieveInd myarray 15
Printing all indexes for array index 15
Index 15, element 0 = 3
Index 15, element 1 = 11
Index 15, element 2 = 6
Index 15, element 3 = 4
Index 15, element 4 = 17
Index 15, element 5 = 12
Index 15, element 6 = 16
Index 15, element 7 = 20
Index 15, element 8 = 21
Index 15, element 9 = 23
0
HTH
set x 5
set y 7
set color($x,$y) blue
set x "1"
set y " 2"
puts "$color($x,$y)"