http://www.perlmonks.org?node_id=838307

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Am sure this is a very simple question, for all you guys ..

But for some reason am not able to figure out, so please forgive me if it is too simple.

Question is, why the following code is not shifting all the data out ?! and keeps the last element of the array as it is even after a full iteration through the array and shift !
@arr = ( 1, 2, 3 ); for my $x ( @arr ) { print "Shifting\n"; shift @arr; print "count: " . scalar @arr; print "data: @arr\n"; } print "\ndata: @arr";


The last print is printing 3 ? I expect it to print nothing ? Why it is not doing so ?

Can anybody explain it better !