I am trying to create something like the following, which will loop through an array and simultaneously remove the first value from the array each time:
My problem is that the printed output is 1,3,5 instead of 1,2,3,4,5,6.
Why am I only getting every second value? I assume the "foreach" is doing some sort of internal shift but how do I get around it?
Any help much appreciated!
Thanks in advance.
Code:
@array = (1,2,3,4,5,6);
foreach $value (@array)
{
shift(@array); ## used elsewhere
print "$value";
}
My problem is that the printed output is 1,3,5 instead of 1,2,3,4,5,6.
Why am I only getting every second value? I assume the "foreach" is doing some sort of internal shift but how do I get around it?
Any help much appreciated!
Thanks in advance.