good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: Why does the Perl conditional operator not do what I expect?by betterworld (Curate) |
on Apr 20, 2009 at 10:50 UTC ( [id://758666]=note: print w/replies, xml ) | Need Help?? |
Running this with perl -MO=Deparse,-p gives: (($condition ? ($a = 2) : $a) = 3);So your problem is operator precedence. You should parenthize the assignments. (The ternary operator is often found on the right-hand side of an assignment, so it has higher precedence.)
In Section
Seekers of Perl Wisdom
|
|