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

Re: ||= operator

Thread Previous | Thread Next
From:
Noah Garrett Wallach
Date:
August 15, 2009 01:25
Subject:
Re: ||= operator
Message ID:
4A85DE7C.3050702@enabled.com
Chas. Owens wrote:
> 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
> 

Okay Chas,

we all found that in the docs.   based on the information you posted. 
what does "||="  do?

Cheers,

Noah


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