Mega Code Archive

 
Categories / Perl / Array
 

Using Pop to remove element from an array

for ( $i = 1; $i <= 5; ++$i ) {    push( @array, $i );                print "@array\n";               } while ( @array ) {    $firstTotal += pop( @array );  # remove last element    print "@array\n";              # display current @array } print "\$firstTotal = $firstTotal\n\n";