Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Re: Re: variable set to 0 ? 0 : 1

by John M. Dlugosz (Monsignor)
on Sep 06, 2002 at 19:01 UTC ( [id://195742]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: variable set to 0 ? 0 : 1
in thread variable set to 0 ? 0 : 1

That's how I used to do it in C/C++ before it had a bool type, when it was necessary to canonize the value.

If that's too idiomatic, using return asbool($status) where that's an inlined function would be readable and just as efficient.

Note that it does a bit more than it does in a stronly-typed language. What if $status is not an int at all? The normal boolism is to treat undef and empty strings as false, also, and in one known case 0e1 is used as zero-but-true. The original test will be different from that; the !! idiom preserves it.

—John

Replies are listed 'Best First'.
Re: Re: Re: Re: variable set to 0 ? 0 : 1
by BrowserUk (Patriarch) on Sep 06, 2002 at 19:17 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-19 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found