If order is important, pop is wrong in both examples:
c:\@Work\Perl\monks>perl -wMstrict -le
"my @array1 = qw/ball bat helmet/;
print qq{\@array1 before: (@array1)};
;;
my @array2;
while (@array1) {
my $item = pop @array1;
print $item;
push(@array2,$item);
}
print qq{\@array2 after: (@array2)};
"
@array1 before: (ball bat helmet)
helmet
bat
ball
@array2 after: (helmet bat ball)
shift does the trick:
c:\@Work\Perl\monks>perl -wMstrict -e
"use Data::Dump qw(dd);
;;
my @array1 = (qw/ball bat helmet/, 0, undef);
dd '@array1 before:', \@array1;
;;
my @array2;
while (@array1) {
my $item = shift @array1;
dd $item;
push(@array2,$item);
}
dd '@array2 after:', \@array2;
"
("\@array1 before:", ["ball", "bat", "helmet", 0, undef])
"ball"
"bat"
"helmet"
0
undef
("\@array2 after:", ["ball", "bat", "helmet", 0, undef])
Give a man a fish: <%-{-{-{-<