I hate statement modifiers. All except "for". Anyway, whenever in doubt place parens and/or check:
$ perl -MO=Deparse -e'push @badVals, $val && next if isBad($val);' push @badVals, $val && next if isBad($val); -e syntax OK $ perl -MO=Deparse -e'(push @badVals, $val && next) if isBad($val);' push @badVals, $val && next if isBad($val); -e syntax OK $ perl -MO=Deparse -e'push @badVals, ($val && next) if isBad($val);' push @badVals, $val && next if isBad($val); -e syntax OK $
Note that all parse the same, and thus probably do not do what you expected it to do. Compare to:
$ perl -MO=Deparse -e'(push @badVals, $val) && next if isBad($val);' push @badVals, $val and next if isBad($val); -e syntax OK $ perl -MO=Deparse,-p -e'push @badVals, $val && next if isBad($val);' (isBad($val) and push(@badVals, ($val && next))); -e syntax OK
update: added -p example after kcott's post.
In reply to Re: order of operations with conditionals at the end
by Tux
in thread order of operations with conditionals at the end
by BeneSphinx
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |