#! /usr/bin/expect --
# Check whether a string is a palindrome
proc cPalin {str} {
set debug 0
# Print the default the string
if {$debug == 1} {
send_user "The default string is $str\n"
}
# Do the palindrome check
set flag 0
for {set i 0; set j [expr [string length $str] - 1]} {$i <= $j} {incr i; incr j -1} {
set aTmp [string index $str $i]
set bTmp [string index $str $j]
if {[string compare -nocase $aTmp $bTmp] != 0} {
set flag 1
break
}
}
# Print the final conclusion
if {$flag == 0} {
send_user "<$str> is a palindrome!\n"
} else {
send_user "<$str> is not a palindrome!\n"
}
}
set str [lindex $argv 0]
if {$str == ""} {
puts "Please input string!"
exit
} else {
cPalin $str
}
# Check whether a string is a palindrome
proc cPalin {str} {
set debug 0
# Print the default the string
if {$debug == 1} {
send_user "The default string is $str\n"
}
# Do the palindrome check
set flag 0
for {set i 0; set j [expr [string length $str] - 1]} {$i <= $j} {incr i; incr j -1} {
set aTmp [string index $str $i]
set bTmp [string index $str $j]
if {[string compare -nocase $aTmp $bTmp] != 0} {
set flag 1
break
}
}
# Print the final conclusion
if {$flag == 0} {
send_user "<$str> is a palindrome!\n"
} else {
send_user "<$str> is not a palindrome!\n"
}
}
set str [lindex $argv 0]
if {$str == ""} {
puts "Please input string!"
exit
} else {
cPalin $str
}