in reply to Re: Mysterious for behavior
in thread Mysterious for behavior
Actually (and this was the point of confusion), I made $_ an alias to $i three times. I would have understood if it had acted like
The PerlMonk tr/// Advocate
where each assignment happens in turn, because of the comma operator, and $_ is aliased to the final result ($i) once. But that didn't happen. I expected each assignment expression to yield the value of its right-hand side, but Perl evaluated it more like:for (scalar($i=3, $i=2, $i=1)) { print "$_ and $i\n"; }
$i=3, $i=2, $i=1; for ($i, $i, $i) { print "$_ and $i\n"; }
The interesting part
I can get the effect I expected by doing this:for (0+($i=3), 0+($i=2), $i=1) { print "$_ and $i\n"; }
The PerlMonk tr/// Advocate
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Mysterious for behavior
by borisz (Canon) on Apr 21, 2004 at 19:46 UTC | |
Re: Re: Re: Mysterious for behavior
by Belgarion (Chaplain) on Apr 21, 2004 at 20:00 UTC | |
Re: Re: Re: Mysterious for behavior
by ysth (Canon) on Apr 21, 2004 at 22:18 UTC | |
by Roy Johnson (Monsignor) on Apr 21, 2004 at 22:25 UTC |
In Section
Seekers of Perl Wisdom