if statement - Perl If-Elsif-Else always going to else -
i have block of code in larger program suppose take letter (a...d) , convert number (0...3). reason jumps down else. here code:
$aa = shift @filearray; chomp($q); chomp($a1); chomp($a2); chomp($a3); chomp($a4); chomp($aa); print "1:$aa\n"; #convert answer number $ab = 0; if ($aa eq "a") { $ab = 0; } elsif ($aa eq "b") { $ab = 1; } elsif ($aa eq "c") { $ab = 2; } else { $ab = 3; } print "2:$ab\n\n";
the output along lines of
1:b 2:3 1:a 2:3 1:d 2:3 1:c 2:3 1:d 2:3 1:b 2:3 1:b 2:3 1:a 2:3 1:d 2:3
now realize @ point subtract 65 ascii value, still want know...what happening?
maybe $aa
contains invisible characters (whitespace, carriage return). verify $aa
contains think does: single character. 1 way check this:
length($aa) == 1
more advanced , more informative checks include:
use data::dumper; local $data::dumper::useqq = 1; print dumper($aa);
and
print join ' ', map { ord } split //, $aa;
and
printf '%v02x\n', $aa;
the last check displays ordinal values every character in $aa
.
Comments
Post a Comment