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

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004313]
[marto]: good morning all, TCIF
[Corion]: Hi marto! Indeed, Crunchy be thanked!
choroba had a Christams party at work yesterday. Slow morning today...
[Corion]: I guess I should not read some discussions on HackerNews - the crowd there is weirdly different - "you have to stay current in tech" (by following all the latest JS trends) is a meme there, but it doesn't really match my experience
[Corion]: At least in my area, experience can beat most new tech anyway because most new tech is just a rehash of things abandoned in the 70s and we still have a lot of that ;)

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2016-12-09 10:15 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (150 votes). Check out past polls.