Consider these examples:
You are post-incrementing your variable. It isn't 'true' until after the and is evaluated. Since the lefthand side of the and is false, the righthand side is never evaluated. This is called "short-circuiting" and it is often very useful.$ perl -le 'print $h++' 0 $ perl -le '0 and print "this will not be printed"' $
As you discovered, you can use a comma to get what you want; you could also change your post-increment to a pre-increment. But I don't think either of those options is the best way to do it. There's really no value in being overly idiomatic. The straight-forward approach is probably best:
while ( <DATA>) { chomp; if ($_ > 5) { $hash{ $_ }++; next; } print; }
-sauoq "My two cents aren't worth a dime.";
In reply to Re: 'and next' question
by sauoq
in thread 'and next' question
by Not_a_Number
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |