Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Converting to boolean

by hv (Prior)
on Jun 17, 2004 at 14:19 UTC ( [id://367628]=note: print w/replies, xml ) Need Help??


in reply to Converting to boolean

When I want clarity, or when I specifically want to avoid an undefined value, I tend to use the trinary operator:

$bool = $x ? 1 : 0;

When I want shortness I tend to use !!$x.

When I'm comparing truthness of two expressions, I factor out one of the !s:

if (!$x == !$y) { ... }

Hugo

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-25 17:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found