Using @array as a condition
# When @array is empty, the condition becomes false; otherwise, it is true.
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";
Related examples in the same category