Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: ||= (poorly documented?)

by frozenwithjoy (Curate)
on Jul 09, 2012 at 05:55 UTC ( #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).

Comment on Re: ||= (poorly documented?)
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2015-05-29 11:40 GMT
Find Nodes?
    Voting Booth?

    In my home, the TV remote control is ...

    Results (583 votes), past polls