in reply to Order of operations
The first message refers you to "Terms and List Operators (Leftward)" in perlop, which says:
print ($foo & 255) + 1, "\n";probably doesn't do what you expect at first glance. The parentheses enclose the argument list for print which is evaluated (printing the result of $foo & 255). Then one is added to the return value of print (usually 1). The result is something like this:
1 + 1, "\n"; # Obviously not what you meant.To do what you meant properly, you must write:
print(($foo & 255) + 1, "\n");See Named Unary Operators for more discussion of this.
...
If any list operator (print(), etc.) or any unary operator (chdir(), etc.) is followed by a left parenthesis as the next token, the operator and arguments within parentheses are taken to be of highest precedence, just like a normal function call.
You can see how Perl is interpreting your code with B::Deparse:
$ perl -MO=Deparse,-p -e 'print (4-1) + 2+3 * (2*2);' ((print(3) + 2) + 12);
|
|---|