Using unshift to insert elements at the front of @array
for ( $i = 1; $i <= 5; ++$i ) {
push( @array, $i );
print "@array\n";
}
for ( $i = 1; $i <= 5; ++$i ) {
unshift( @array, $i ); # add $i to front of @array
print "@array\n"; # display current @array
}
Related examples in the same category