Re: multiple local vars in a foreach loopby LanX (Chancellor)
|on Jan 31, 2013 at 08:40 UTC||Need Help??|
The simple answer
already does what you want. =)
The long answer!
Regarding your initial question: "unfortunately not"!
Perl5 doesn't provide a built-in way to have multiple loop vars in foreach.
There are several workarounds with while loops:
but these workarounds have been discussed so often in the monastery that I'd prefer to link them after finding them.
In this case (ignoring the solution on top) I would do something with splice:
You need to copy @array in case I wanna keep the initial elements after the loop.
Originally I proposed this code
But I was bitten by precedence, the code does it the wrong way around: