Front page | perl.beginners |
Postings from August 2009
Re: ||= operator
From: Chas. Owens
August 15, 2009 10:58
Re: ||= operator
Message ID: email@example.com
On Fri, Aug 14, 2009 at 18:01, Noah Garrett
> Telemachus wrote:
>> On Fri Aug 07 2009 @ 2:55, Admin wrote:
>>> Hi there,
>>> is there a page that explains the ||= operator and similar operators?
>>> google is not quite finding the special characters in the first 10 hits.
>> Google and punctuation don't mix well, apparently.
>> In any case, try perldoc perlop in a terminal or online:
> I searched the docs for ||=
> here is the result
> Search results for query "||="
All the information you need is in [perlop], it just requires you
to infer the behavior of ||= from the information given. I am working
on a [reference version of perlop] (called perlopref) that will
hopefully make this easier. The relevant pieces of perlop are
"=" is the ordinary assignment operator.
Assignment operators work as in C. That is,
$a += 2;
is equivalent to
$a = $a + 2;
although without duplicating any side effects that dereferencing the
lvalue might trigger, such as from tie(). Other assignment operators
work similarly. The following are recognized:
**= += *= &= <<= &&=
−= /= |= >>= ||=
.= %= ^= //=
Although these are grouped by family, they all have the precedence of
This tells you that ||= is like +=, that is $a ||= 2 is the same as $a
= $a || 2. Logical or is well documented in its section of perlop:
C−style Logical Or
Binary "||" performs a short‐circuit logical OR operation. That is, if
the left operand is true, the right operand is not even evaluated.
Scalar or list context propagates down to the right operand if it is
 : http://perldoc.perl.org/perlop.html
 : http://github.com/cowens/perlopref
The most important skill a programmer can have is the ability to read.