Do you know where your variables are? | |
PerlMonks |
Re: Why does a full iteration over array & shift is not emptying the arrayby moritz (Cardinal) |
on May 04, 2010 at 13:39 UTC ( [id://838308]=note: print w/replies, xml ) | Need Help?? |
Modifying the array you're iterating over is a bad idea.
The explanation here is that $x is bound to the first array item (1) in the first iteration, and to the second array item (which is then 3) in the second iteration. At that time there's no third item in the array anymore, and the body of the loop is executed only twice (as you can see from your debugging output). It becomes a bit clearer if you also print out $x in the loop body.
In Section
Seekers of Perl Wisdom
|
|