for the first time, the post increment operator sets $H_count to 1 and returns 0, i.e. a false value. Therefore, the statement following the and operator is not executed. The next time you run the same post-increment statement, it will return 1 (and subsequently other true values) and it will work fine as shown in the following test under the Perl debugger:$H_count ++ and ...
This would work fine with the pre-increment operator:DB<1> $h++ and print "foo"; DB<2> $h++ and print "foo"; foo
The solution suggested by swl is probably better because there is no hidden surprise in it.DB<3> ++$i and print "foo"; foo
As a side comment, please note that in these two code lines:
the first line isn't useful, because the second code line will remove all trailing white spaces, including the \r Windows CR character.$line =~ s/\r//g; # removes windows CR characters $line =~ s/\s+$//; # removes trailing white spaces
In reply to Re^2: List comparison problem
by Laurent_R
in thread List comparison problem
by perlmonkster
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |