Given the following output, how would I always select the number
corresponding to the text "green"?
-----------------
1: red
2: blue
3: yellow
4: green
5: purple
6: black
7: brown
8: grey
9: orange
10: pink
Choose:
Any help or direction is appreciated.
Thanks,
Joe
Assuming that you can get the "output" into a variable, the following
code will build a mapping of color names to numbers which can be used
find the number associated with "green":
==============================
set output {
-----------------
1: red
2: blue
3: yellow
4: green
5: purple
6: black
7: brown
8: grey
9: orange
10: pink
Choose:
}
foreach line [split $output \n] {
set elements [split $line :]
if {[llength $elements] == 2} {
set number [string trim [lindex $elements 0]]
if {[string is integer $number]} {
set color [string trim [lindex $elements 1]]
set colorMap($color) $number
}
}
}
parray colorMap
puts $colorMap(green)
==============================
The output of which is:
------------------------------
colorMap(black) = 6
colorMap(blue) = 2
colorMap(brown) = 7
colorMap(green) = 4
colorMap(grey) = 8
colorMap(orange) = 9
colorMap(pink) = 10
colorMap(purple) = 5
colorMap(red) = 1
colorMap(yellow) = 3
4
------------------------------
--
Andrew Mangogna
expect -re {(\d+): green.*Choose: *$} {
set green_choice $expect_out(1,string)
}
send -- "$green_choice\r"
--
Glenn Jackman
Ulterior Designer
Joe