in reply to foreach problem with shift

From Dominus blog

On the first iteration, the loop processes the first element in the array. On the second iteration, the loop processes the second element in the array, whatever that element is at the time the second iteration starts, whether or not that was the second element before. On the third iteration, the loop processes the third element in the array, whatever it is at that moment. And so the loop continues, terminating the first time it is called upon to process an element that is past the end of the array.

If you don't want that behavior, then use the foreach as follows

foreach ((), @arr)

I also suggest you to have a look at How foreach decides