in reply to Why does a full iteration over array & shift is not emptying the array

Why is already explained by others. Here's another alternative:
for my $x (@{[]} = @arr) { ... }
this makes a copy of the elements of @arr to loop over, without using a (named) variable.

Replies are listed 'Best First'.
Re^2: Why does a full iteration over array & shift is not emptying the array
by almut (Canon) on May 04, 2010 at 17:02 UTC

    FWIW, adding an empty list also makes a copy of the elements (on the internal stack) to iterate over:

    for my $x ((), @arr) { ... }