Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: shift and logical or

by rjt (Deacon)
on Nov 17, 2012 at 13:46 UTC ( #1004313=note: print w/ replies, xml ) Need Help??


in reply to shift and logical or

Good replies so far, so I won't steal anyone's monastic thunder, although I'll add that Perls >= 5.10 have the logical defined-or operator, //. Often this is what you really want, but since there is a lot of code in the wild that pre-dates it, you may notice disproportionate use of ||.

The difference is simple:

  1. Use $a //= 'foo'; when you want to assign 'foo' to $a if $a is not defined.
  2. Use $a ||= 'foo'; when you want to assign 'foo' to $a if $a has a false value, such as zero or an empty string.


Comment on Re: shift and logical or
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2014-09-22 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (198 votes), past polls