P is for Practical | |
PerlMonks |
Re^2: Surprised by Perl parse of ternary operatorby moritz (Cardinal) |
on Dec 16, 2011 at 12:50 UTC ( [id://943937]=note: print w/replies, xml ) | Need Help?? |
It is indeed a bit weird since ?: has higher precedence than = If it were any different, the useful idiom
would be parsed as
which totally wouldn't make sense. It's useful to optimize the operator precedence level for idiomatic use, not for misunderstood corner cases. That said, it is possible to both allow the common case and detect the error; that's what Perl 6 does:
But I guess Perl 5 won't do it soon, because it'll break some obfuscations that successfully "use" that feature somewhere.
In Section
Seekers of Perl Wisdom
|
|