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.
use 5.010; sub apple { say "apple" } sub banana { say "banana" } sub cherry { say "cherry" } apple && (banana || cherry)
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:
banana apple
However, the output I get is:
apple banana
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.
In reply to Operator precedence by muba
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |