Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: OEO, a zero that evaluates to true?

by n3dst4 (Scribe)
on Jan 08, 2002 at 21:40 UTC ( #137191=note: print w/ replies, xml ) Need Help??


in reply to OEO, a zero that evaluates to true?

Blakem pointed you to a good resource, but basically you've hit Context. In Perl, when you:

Do a mathsy thing to a string (like '0E0' or 'oink' or '57Fred')
Any digits at the start are taken as the value and the rest is lost. So (5 + '0E0') == (5 + '0') == (5 + 0) == 5
Do a stringy thing to a string
It stays the way it is
Do a neutral thing to a string, like checking for truth
It again gets left the way it is.
So in your case, '0E0' is true as a string, because it's neither empty nor just the string '0', but false as a number because it gets whittled down to the value 0 (the digits at the start).


Comment on Re: OEO, a zero that evaluates to true?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-12-20 19:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (97 votes), past polls