Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Question about ternary condition

by dave_the_m (Monsignor)
on Jun 28, 2005 at 09:46 UTC ( [id://470547]=note: print w/replies, xml ) Need Help??


in reply to Question about ternary condition

Prececedence:
(exists $hash{$_} and $hash{$_} eq 'on') ? $result = 'OK' : $result = 'KO'
is parsed as
( cond ? $result = 'OK' : $result) = 'KO'
and if cond is true, gets reduced to
($result = 'OK') = 'KO'
so you assign OK, then KO, to $result. In any case, your first syntax is preferable, and the use of exists is unnecessary as the only keys you're testing are the the keys of the hash, so they must always exist

Dave.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-23 09:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found