|Problems? Is your data what you think it is?|
Operator precedenceby muba (Priest)
|on Jan 12, 2013 at 23:01 UTC||Need Help??|
muba has asked for the
wisdom of the Perl Monks concerning the following question:
According to perldoc perlop, terms have the highest precedence of everything:
A TERM has the highest precedence in Perl. They include variables, quote and quote-like operators, any expression in parentheses ...
Please consider the following code.
Given that expressions in parentheses have topmost priority, one would expect Perl to evaluate (banana || cherry) first, which would boil down to say "banana" which would return 1, and only then to evaluate apple && (1).
So the output I more or less expected is:
However, the output I get is:
Please shed some light on this. Why isn't the parenthesed expression evaluated first? I understand the short circuiting nature of the logical operators — for one, this explains why cherry isn't outputted at all, but I fail to understand how && seems to have higher precedence than ( EXPR ), despite the information in the documentation.