HACKER Nora wrote:
Hello list,
Hello,
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
perldoc perlsyn [ SNIP ] Foreach Loops [ SNIP ] 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. John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/