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

Re: ||= (poorly documented?)

by frozenwithjoy (Priest)
on Jul 09, 2012 at 05:55 UTC ( [id://980652]=note: print w/replies, xml ) Need Help??


in reply to ||= (poorly documented?)

You are almost correct in understanding how it works. Whatever is on the right side of the ||= operator is used if the left side evaluates to undef, like you said; however, it is also used if the left evaluates to false.

my $string; $string ||= "Oh noes! Your variable was undef or false!";

I believe //, on the other hand, only tests for whether the left side is defined (but not for truthiness).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2025-06-22 06:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.