Sorry, c&p-accident...

The proper result should be of course:

oracle:/opt/data/magna/wartung/work/nora> ./test.pl
Arr1: one
Arr2: 1
Arr2: 2
Arr1: two
Arr2: 1
Arr2: 2
Arr1: three
Arr2: 1
Arr2: 2

Regards, 
Nora 



> -----Ursprüngliche Nachricht-----
> Von: HACKER Nora
> Gesendet: Montag, 27. September 2010 09:20
> An: beginners@perl.org
> Betreff: Problem with foreach loop
> 
> Hello list,
> 
> Could someone please explain why this test script:
> 
> my @arr1 = qw(one two three);
> my @arr2 = qw(1 2 3);
> 
> foreach my $arr1 ( @arr1 ) {
>         print "Arr1: $arr1\n";
>         foreach my $arr2 ( @arr2 ) {
>                 print "Arr2: $arr2\n";
>                 if ( $arr2 eq '2' ) {
>                         shift @arr1;
>                 }
>         }
> }
> 
> produces that result:
> 
> oracle:/opt/data/magna/wartung/work/nora> ./test.pl
> Arr1: one
> Arr2: 1
> Arr2: 2
> Arr2: 3
> Arr1: three
> Arr2: 1
> Arr2: 2
> Arr2: 3
> 
> whereas I had expected the output to be like this:
> 
> oracle:/opt/data/magna/wartung/work/nora> ./test.pl
> Arr1: one
> Arr2: 1
> Arr2: 2
> Arr2: 3
> Arr1: two     # why not?
> Arr2: 1               # why not?
> Arr2: 2               # why not?
> Arr1: three
> Arr2: 1
> Arr2: 2
> Arr2: 3
> 
> Thanks in advance!
> 
> Regards,
> Nora
> 
> 


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to