Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Question about ternary condition

by dave_the_m (Monsignor)
on Jun 28, 2005 at 09:46 UTC ( #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? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2022-12-05 09:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?