Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: ||= (poorly documented?)

by Anonymous Monk
on Jul 09, 2012 at 06:36 UTC ( #980659=note: print w/ replies, xml ) Need Help??


in reply to ||= (poorly documented?)

Yep, that is right and it works the way it reads.

perl -e "my $shoo = 50; $shoo ||= 100; print $shoo;"
Prints
50
Should be the same as,
perl -e "$shoo=50; $shoo = ($shoo)?50 : 100;print $shoo;"
If you scroll down in perlop you'll see that style used to describe what // does, so they appear to be equivalent.

Celebrate Intellectual Diversity


Comment on Re: ||= (poorly documented?)
Select or Download Code
Replies are listed 'Best First'.
Re^2: ||= (poorly documented?)
by frozenwithjoy (Curate) on Jul 09, 2012 at 06:47 UTC
    If you scroll down in perlop you'll see that style used to describe what // does, so they appear to be equivalent.
    || tests for truthiness (and, therefore, definedness), whereas // only tests for definedness.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2015-08-31 09:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...













    Results (354 votes), past polls