in reply to Array Processing

Change your loop as follows, and the script will work properly:

local $" = "\n"; my @array = ( 1 .. 5 ); while( @array ) { my $item = shift @array; print "Removed value $item from the front of \@array\n"; } print "Deleted array content:\n@a\n";

foreach iterates over the array's elements, but you keep changing them, and that has the potential of driving you mad. while() continues looping as long as its conditional is true. @a evaluated in scalar context returns the number of elements remaining in the array. This is a much better test, because as soon as there are zero elements remaining, the while() loop's conditional becomes false, and you stop looping.


Dave