Hello,
I am wondering how I can get a variable to contain more than one value.(like a korn shell array) Then how can I get the script to run a for loop on each entry in the variable.
#The foreach loop is commonly used.
foreach y [array name myhosts] x $myhostslist {
catch {puts "ARRAY: $myhosts($y)"}
catch {puts "LIST : $x"}
}
#end
You can use the familiar C for loop as well with
a list easily:
for {set x 0} {$x <= [llength $myhostslists]} {incr x} {
puts [lindex $myhostslist $x]
}
Or by using numeric indices for the tcl array:
array set myhosts {
1 127.0.0.1
2 127.255.255.255
}
for {set x 1 } {$x < [array size myhosts]} {incr x} {
puts "$x = $myhosts($x)"
}
Another cool thing you can do with tcl lists and arrays is search for keys or patterns in indices, and lists using
the [array name "globpatternhere"], and lsearch commands.
Remember that expect is a superset of tcl and is based
on tcl and uses all of the control and data constructs
in tcl. Getting to know tcl is the best way to use expect.
A better forum for your questions is the tcl group here at Tek-Tips.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.