On Thu, May 1, 2008 at 10:27 AM, Chas. Owens <[EMAIL PROTECTED]> wrote:
> On Thu, May 1, 2008 at 10:15 AM,  <[EMAIL PROTECTED]> wrote:
>  > Hi Members,
>  >  Can someone explain why the foreach loop did not iterate 10 times.
>  snip
>
> >  foreach (@data){
>  >     splice @data,0,1;
>  >     print "printing [EMAIL PROTECTED] = @data\n";
>  >  }
>  snip
>
>  Mucking about with the array being iterated over breaks the iterator.
snip

from perldoc perlsyn or http://perldoc.perl.org/perlsyn.html#Foreach-Loops
       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.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to