in reply to $#array issue
You've got your $end commented out (update: your example runs fine when it's not). :) Use strict and warnings. It'll save you much trouble. Also, tracking an index in this situation is a bit artificial. You're already destroying the array so just use that as your end point (the existence of elements in the array).
use warnings; use strict; my @array= ( 1 .. 9 ); while ( @array ) { my $last = pop @array; print "$last\n"; } # ...or... my @array= ( 1 .. 9 ); print "$_\n" while $_ = pop @array;
|
|---|