The source program is:
#! /usr/bin/perl -w
my @test =qw /test1 test2 test3 test4 test5 test6 test7/;
my $count =0;
$total = @test;
foreach (@test){
my $n= shift (@test);
$count++;
print "$n $count of $total\n";
print "@test\n";
}
print "\n\n==================\n\n";
foreach (@test){
$count++;
print "$_ $count of $total\n";
print "@test\n";
}
Then the executed result is:
test1 1 of 7
test2 test3 test4 test5 test6 test7
test2 2 of 7
test3 test4 test5 test6 test7
test3 3 of 7
test4 test5 test6 test7
test4 4 of 7
test5 test6 test7
==================
test5 5 of 7
test5 test6 test7
test6 6 of 7
test5 test6 test7
test7 7 of 7
test5 test6 test7
My question is why in the first foreach cycle @test which has the
(test5 test6 test7) are not executed. Which means only half of orginal
@test appear in the first foreach cycle. I know it is the problem of
shift. But I do not know the reason.
Thanks.
Frank
---------------------------------
Do You Yahoo!?
150万曲MP3疯狂搜,带您闯入音乐殿堂
美女明星应有尽有,搜遍美图、艳图和酷图
1G就是1000兆,雅虎电邮自助扩容!