Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2018-05-23 07:02 GMT
Find Nodes?
    Voting Booth?