On Mon, May 06, 2002 at 08:25:11PM -0700, William R Ward wrote:
> [EMAIL PROTECTED] writes:
> > Eew. That looks like a bug in perl somewhere.
> >
> > shuffle 1 .. 10; # Fine.
> > shuffle 1, 2, 3, 4, 5, 6, 7, 8, 9, 10; # Not ok.
>
> [Perl5-porters is CC'd on this. Note to them: shuffle() does a
> for/foreach loop over @_ and modifies the insides. Followup set to
> perl5-porters, but I post via NNTP and don't know if SMTP people will
> see that...]
>
> I would not be at all surprised if Perl is doing some optimization to
> translate
> for(1..10) {...}
> to
> for($i=1;$i<10;++$i){local($_)=$_[$i]; ... }
> or something roughly equivalent. To reduce it even farther, one of
> these works and the other doesn't - try it and see:
>
> perl -e 'for (1..10) { $_++; }'
> perl -e 'for (1,2,3,4,5,6,7,8,9,10) { $_++; }'
>
> Is this a known bug?
I think perlsyn has had this for a while:
If any element of LIST is an lvalue, you can modify it by modifying
VAR inside the loop. Conversely, if any element of LIST is NOT an
lvalue, any attempt to modify that element will fail. In other words,
the C<foreach> loop index variable is an implicit alias for each item
in the list that you're looping over.
That the first one works (as in, "doesn't fail", what it *does*, I
don't know) is to be considered an accident since I do not see any
lvalues in either.
But that's a post-5.8.0 issue from my perspective.
> --Bill.
>
> --
> William R Ward [EMAIL PROTECTED] http://www.wards.net/~bill/
> -----------------------------------------------------------------------------
> AMAZING BUT TRUE: There is so much sand in northern Africa that if it were
> spread out it would completely cover the Sahara Desert!
--
$jhi++; # http://www.iki.fi/jhi/
# There is this special biologist word we use for 'stable'.
# It is 'dead'. -- Jack Cohen