Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Why does the Perl conditional operator not do what I expect?

by betterworld (Curate)
on Apr 20, 2009 at 10:50 UTC ( #758666=note: print w/replies, xml ) Need Help??


in reply to Why does the Perl conditional operator not do what I expect?

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.)

Replies are listed 'Best First'.
Re^2: Why does the Perl conditional operator not do what I expect?
by Anonymous Monk on Apr 20, 2009 at 11:07 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://758666]
help
Chatterbox?
[Corion]: Tabish: What are "tow" packages? Maybe you want to use PAR::Packer to copy them and your main program into one (ugly) script for distribution?

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2017-12-11 09:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (288 votes). Check out past polls.

    Notices?