Re: [perl #75720] for(@a) optimisation causes problems

[email protected] ("Chas. Owens")
Newsgroups perl.perl5.porters
Message-ID <[email protected]>
On Sun, Jun 13, 2010 at 21:23, Father Chrysostomos
<[email protected]> wrote:
snip
> $ perl -le' @a = (1,2,3); print shift @a for @a'
> 1
> 2
snip

This a documented as a bad thing to do in [perlsyn][1]:

If any part of LIST is an array, foreach will get very confused if you
add or remove elements within the loop body, for example with splice.
So don't do that.

[1] : http://perldoc.perl.org/perlsyn.html#Foreach-Loops




-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.