Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: multiple local vars in a foreach loopby LanX (Saint) |
on Jan 31, 2013 at 08:40 UTC ( [id://1016253]=note: print w/replies, xml ) | Need Help?? |
The simple answermy %hash=@keys; already does what you want. =)
UPDATES
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.
SpliceIn 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.
Older discussionsgoogling the monastery for splice+natatime
Cheers Rolf
ErrataOriginally I proposed this code
But I was bitten by precedence, the code does it the wrong way around:
In Section
Seekers of Perl Wisdom
|
|