Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by abell (Chaplain)
on Sep 06, 2002 at 08:06 UTC ( [id://195595]=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

Nice golf, but your solution never returns 0, which is what the original snippet does. Furthermore, if $status is '0E0' or '0.0' it returns 1, because they both are true values, though numerically zero.
See:
for ( 0, 0.0, "0", "0.0", "0E0", 1, "1" ) { print $_, "\t", !!$_, "\t", ( $_==0 ? 0 : 1 ), "\n"; }

prints out
0               0
0               0
0               0
0.0     1       0
0E0     1       0
1       1       1
1       1       1


Best regards

Antonio Bellezza

Update: As pointed out in other posts, the same behaviour of "0.0" and "0E0" is true for strings not representing numbers, which have true values, but behave as 0 in numeric comparison. The difference is a warning of type
Argument "xyz" isn't numeric in numeric eq (==) at - line 3.
when -w is enabled.

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

    True! Some things don't translate well from my former (C) world into Perl. I hadn't considered the possibility (or perversity) of setting a status value to a string representation of zero.

    It wasn't aimed at the OP in anycase.


    Well It's better than the Abottoire, but Yorkshire!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-24 18:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found