On Mon, 18 Apr 2005, Lloyd Sartor wrote:
> Jerry Kassebaum wrote on 04/17/2005 06:56:29 AM:
> >
> > $x=10;
> >
> > $x=$x++;
> >
> > print "$x\n";
> >
> > $x=10;
> >
> > $y=$x++;
> >
> > print "$x\n";
> >
> > #Results: $x=10, $x=11.
> > #I understand it, but I think it's weird anyway.
> >
> 
> The first result ($x=10) puzzles me. Are not the $x on the LHS and RHS
> refering to the same scalar? I would think that $x would be assigned the
> value of $x (10), and then be post-incremented, resulting in 11.
> 
> Explanation?

The code is equivalent to:

  $x = 10;
  $tmp = $x++;
  $x = $tmp;

Think about how a more complex expression would need to be compiled:

  $x = 10;
  $x = $x++ + $x++;

turns into

  $x = 10;
  $tmp1 = $x++;
  $tmp2 = $x++;
  $x = $tmp1 + $tmp2;

Setting $x to 21.  The $tmp variables are just stack locations containing
intermediate results of subexpressions.

Cheers,
-Jan 
  


_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to