Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: ||= (poorly documented?)

by dsheroh (Monsignor)
on Jul 09, 2012 at 09:23 UTC ( [id://980677]=note: print w/replies, xml ) Need Help??


in reply to Re: ||= (poorly documented?)
in thread ||= (poorly documented?)

There is a rather strange thing that can happen in Perl.
It is possible for Perl to return a "true", "zero" value.
It does this by returning the string "0E0": 0 * 10**1 =0 numerically, but that evaluates to "true" in a logical sense.
This works because there are only two strings which evaluate as false in Perl: "" and "0".

Any other string which begins with one or more zeroes followed by a non-digit character will by logically true (since it's not one of the two false strings) while still having the value 0 when evaluated as a number. This actually will also work with strings that start with a non-numeric character (true as a boolean, 0 as a number), but, if warnings are enabled (as they generally should be), it will complain that "Argument "..." isn't numeric" if you try to use it as a number.

Aside from "0E0", the other string I often see used for this purpose (I'm not sure which is more common) is "0 but true".

Replies are listed 'Best First'.
Re^3: ||= (poorly documented?)
by Marshall (Canon) on Jul 09, 2012 at 09:37 UTC
    I don't see how you and I are in any kind of disagreement.
      We're not. You seemed surprised that this works, so I provided an explanation for why it works.

Log In?
Username:
Password:

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

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

    No recent polls found