Mega Code Archive

 
Categories / Perl / Array
 

While there are more elements in @array, remove each element with shift

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