You can use tcl lists or the tcl array.
Try this example.
#!/usr/bin/expect
#start
array set myhosts {
localhost 127.0.0.1
localbroadcast 127.255.255.255
}
set myhostslists [list 127.0.0.1 127.255.255.255]
#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.
HTH