in reply to Re: List comparison problem
in thread List comparison problem
The reason of the problem is that when you run:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: List comparison problem
by hippo (Bishop) on Aug 16, 2019 at 09:34 UTC | |
by Laurent_R (Canon) on Aug 16, 2019 at 21:14 UTC | |
by perlmonkster (Initiate) on Aug 17, 2019 at 00:52 UTC |
In Section
Seekers of Perl Wisdom