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

Re: ||= operator

Thread Previous | Thread Next
From:
Owen
Date:
August 15, 2009 02:48
Subject:
Re: ||= operator
Message ID:
586039af5b4792a4a1054202fd502885.squirrel@www.tip.net.au

> 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:
>> http://perldoc.perl.org/perlop.html
>>
>
> thanks
>
> I searched the docs for ||=
> here is the result
>
> Search results for query "||="



I am no expert on this, and not being able to find any example of ||=,
I wrote this;


#!/usr/bin/perl

use strict;

my $a = $a || 2;

print "$a\n";

$a = 3;

my $a = $a || 2;

print "$a\n";

my $a = $a ||= 2;

print "$a\n";

undef $a;

my $a = $a ||= 2;

print "$a\n";


So I come to the conclusion that || and ||= are the same, but in terms
of precedence, || will have the higher precedence than ||=


-- 



Owen


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