|
|
|
good chemistry is complicated, and a little bit messy -LW |
|
| PerlMonks |
Re^2: Surprised by Perl parse of ternary operatorby eyepopslikeamosquito (Canon) |
| on Dec 16, 2011 at 12:52 UTC ( #943938=note: print w/ replies, xml ) | Need Help?? |
|
Curiously, both Ruby and PHP, both with the same relative precedence as Perl for the ternary and assignment operators, bend the rules differently. For example, this Ruby program: and PHP program: both run without error, but, unlike Perl (which produces config=k2), both Ruby and PHP produce config=k1. Arguably, all three languages should produce a syntax error. Update: gcc produces a syntax error "f.c:6: error: lvalue required as left operand of assignment" with this test program (further update: g++ compiles it happily though and with the same semantics as the Ruby and PHP test programs): Adding parentheses to line 6: makes it work the same as the Ruby and PHP test programs.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||