Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: ternary conditional help

by haukex (Archbishop)
on Nov 28, 2016 at 20:42 UTC ( [id://1176733]=note: print w/replies, xml ) Need Help??


in reply to ternary conditional help

Hi opaltoot,

tybalt89 already gave you the answer, I just wanted to note you can use B::Deparse to see how Perl interprets your code for yourself (I replaced 1 with $x to prevent optimization):

$ perl -MO=Deparse,-p -e '$x ? $a = 2 : $b = "x";' (($x ? ($a = 2) : $b) = 'x'); $ perl -MO=Deparse,-p -e '$x ? ($a = 2) : ($b = "x");' ($x ? ($a = 2) : ($b = 'x'));

See also Operator Precedence and Associativity.

Although you might want to consider if using the ternary operator like that will help the legibility of the code :-)

Hope this helps,
-- Hauke D

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1176733]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (8)
As of 2024-03-28 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found