go ahead... be a heretic | |
PerlMonks |
Re^2: Why does the first $c evaluate to the incremented value in [$c, $c += $_] ?by smls (Friar) |
on Mar 05, 2014 at 12:45 UTC ( [id://1077073]=note: print w/replies, xml ) | Need Help?? |
Well, quote-like operators have higher precedence than +=, so your example can still be explained by the "sub-expressions with higher-precedence operators are evaluated first" rule. And in the last example, both shift's have the same precedence, so it goes from left to right "as a last resort". Although, come to think of it, terms are technically supposed to have highest precedence. Yet for some reason, term subexpressions are evaluated last (see my demonstration using tied scalars above). All things taken together, it seems the rules for expression evaluation order in Perl can be described like so:
Which still does not answer the question of "Why on earth would it be defined like that?", though. I really don't think it contributes to DWIM. I think it would be more intuitive if the third rule were simply:
Maybe it's a performance optimization though, because it allows the compiler to only fetch the values of term once it actually needs to evaluate their parent expression?
In Section
Seekers of Perl Wisdom
|
|