in reply to Re^2: Operator precedence of unary plus (Bug or Feature)
in thread Operator precedence of unary plus (Bug or Feature)
I think this special parsing is restricted to print and say.Perl does not have to apply heuristics if there's only one way of parsing it. In most cases, the only way to parse the plus sign will either be as binary operator, or as a unary operator.
The plus in this snippet: "5 +6" will in most other cases be interpreted as a binary operator, no matter how many whitespaces.
This will print [Foo 6] no matter how many whitespace you use around the +. This actually surprised me, I would have expected Perl to apply the same heuristics as the OP encountered.package Foo; sub bar {say "[@_]"} package main; bar Foo + 6;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Operator precedence of unary plus (Bug or Feature)
by LanX (Saint) on Feb 05, 2012 at 18:22 UTC | |
by JavaFan (Canon) on Feb 05, 2012 at 20:29 UTC | |
by JavaFan (Canon) on Feb 05, 2012 at 20:22 UTC |