To add a statement of "print $_" follow the foreach, you will see what
was happening.

foreach (@data){
   print "$_\n";
   splice @data,0,1;
   print "printing [EMAIL PROTECTED] = @data\n";
}

On Thu, May 1, 2008 at 10:15 PM,  <[EMAIL PROTECTED]> wrote:
> Hi Members,
>  Can someone explain why the foreach loop did not iterate 10 times.
>
>  Thanks
>
>  #################
>  use strict;
>  use warnings;
>
>  my @data = (1..10);
>
>  foreach (@data){
>     splice @data,0,1;
>     print "printing [EMAIL PROTECTED] = @data\n";
>  }
>
>  ##### results ###########
>  printing @data = 2 3 4 5 6 7 8 9 10
>  printing @data = 3 4 5 6 7 8 9 10
>  printing @data = 4 5 6 7 8 9 10
>  printing @data = 5 6 7 8 9 10
>  printing @data = 6 7 8 9 10



-- 
J. Peng - QQMail Operation Team
eMail: [EMAIL PROTECTED] AIM: JeffHua

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


Reply via email to