This loop is supposed to read each line of a list, if it starts with a digit, set that digit to the port number, if it contains a given pattern, assign that pattern to to a second variable and only write to the log file if "FAIL" is in the variable.
What I'm stuck with, is that the last if statement determining whether or not to write to the log file, does not work if I place it in the foreach loop. An error "can't read "flipstatus": no such variable" is generated even though that variable should have been defined in the loop above. Are there any obvious mistakes in the code or is there a different way to format the loop
Code:
set result $expect_out(buffer)
set format [split $result "\n"]
set item1 [lindex $format end]
set host [string trimright $item1 "#"]
foreach line $format {
if { [string index $host end] eq "w" } {
if { [string is digit [string range $line 2 3]] == 1 } {
set local_port [string range $line 2 3]
if { [string index [lsearch -inline -regexp $line ".../.*/.*"] end] eq "0" } {
set flipstatus "[lsearch -inline -regexp $line ".../.*/.*"] FAIL"
} else { set flipstatus [lsearch -inline -regexp $line ".../.*/.*"]
}
}
} elseif { [string index $host end] eq "e" } {
if { [string is digit [string range $line 2 3]] == 1 } {
set local_port [string range $line 2 3]
if { [string index [lsearch -inline -regexp $line ".../.*/.*"] end] eq "9" } {
set flipstatus "[lsearch -inline -regexp $line ".../.*/.*"] FAIL"
} else { set flipstatus [lsearch -inline -regexp $line ".../.*/.*"]
}
}
}
if { [string index $flipstatus end] eq "L" } {
puts $log "$host\n $local_port, $flipstatus\n"
}
}
Thanks Ahead