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:
- Use $a //= 'foo'; when you want to assign 'foo' to $a if $a is not defined.
- Use $a ||= 'foo'; when you want to assign 'foo' to $a if $a has a false value, such as zero or an empty string.