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

Re: ||= operator

Thread Previous | Thread Next
Uri Guttman
August 10, 2009 13:03
Re: ||= operator
Message ID:
>>>>> "SHC" == Shawn H Corey <> 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 Guttman  ------  -------- --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- ---------
---------  Gourmet Hot Cocoa Mix  ---- ---------

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About