develooper Front page | perl.beginners | Postings from August 2009

Re: ||= operator

Thread Previous | Thread Next
From:
Chas. Owens
Date:
August 7, 2009 16:15
Subject:
Re: ||= operator
Message ID:
58ce48dc0908071615w429c7a44rf22a06b3f1c9f75f@mail.gmail.com
On Fri, Aug 7, 2009 at 18:42, Admin<admin@enabled.com> wrote:
> Shawn H. Corey wrote:
>>
>> 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.
>>>
>>>
>>
>> See http://perldoc.perl.org/perlop.html#Assignment-Operators
>>
>>
>
>
> thanks Shawn But I searched the page and there is nothing discussing ||=
snip

from perldoc perlop
       Assignment Operators

       "=" 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:

           **=    +=    *=    &=    <<=    &&=
                  −=    /=    |=    >>=    ||=
                  .=    %=    ^=           //=
                        x=

       Although these are grouped by family, they all have the precedence of
       assignment.

Perhaps you are confused by what

$a = $a || 2;

does?  In that case look at the [section of perldoc perlop that deals
with the || operator][1]:

       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
       evaluated.

[1] : http://perldoc.perl.org/perlop.html#C-style-Logical-Or

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About