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

Re: ||= operator

Thread Previous | Thread Next
From:
Uri Guttman
Date:
August 10, 2009 13:03
Subject:
Re: ||= operator
Message ID:
877hxb5te8.fsf@quad.sysarch.com
>>>>> "SHC" == Shawn H Corey <shawnhcorey@gmail.com> writes:

  SHC> You're right.  I keep forgetting the lhs's can have side effects too.


  SHC> But consider:

  SHC> perl -le '$x=7;$x*=2+3;print $x'

  SHC> vs.

  SHC> perl -le '$x=7;$x=$x*2+3;print $x'

that has nothing to do with the left hand side. it is just part of the
effect of *= where the right side is evaluated in its entirety and then
* with the left side. that is one point of the op= ops, the right side
is an entire expression which is then applied to the left side with the
op. parsing it as the op is there on the right would also break the
other rule of the op= which is the left side is only evaluated one
time. this is critical for speed (saving deep reference lookups) or
multiple accesses (tied vars).

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

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