Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2015-10-10 08:15 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (255 votes), past polls