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

Re: ||= operator

Thread Previous | Thread Next
From:
Bryan R Harris
Date:
August 10, 2009 08:22
Subject:
Re: ||= operator
Message ID:
C6A5A56B.35493%Bryan_R_Harris@raytheon.com

> Admin 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 ||=
>> 
>> 
> 
> You're right.  The operator only appears once and is not explained.  The
> best it does is infer how it might work.  And as for the C reference...
> It's about time the perldocs are redone; made more complete and without
> any references to other languages.


I think it's saying that just like:

  $a += 2;

is the same as:

  $a = $a + 2;

similarly:

  $a ||= 3;

is the same as:

  $a = $a || 3;

... implying if $a is false, $a gets set to 3, otherwise it stays at
whatever it was.

- B




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