Using unshift to insert elements at the front of @array : unshift « Array « Perl






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

1.unshift places data to the front of an array
2.The unshift function prepends LIST to the front of the array.
3.unshift array