basically I'm asking: how do I replace the foreach loops with for loops?
And I asked why you want to do that. It's like asking how to remove weeds with kitchen utensils when you have perfectly good gardening tools. They're kinda similar, but they have different purposes.
You have list over which you want to iterate. That's what "foreach" loops do. Counting ("for") loops, on the other hand, cannot iterate over lists. It's possible to store the list in an array, and loop over the indexes of the array, but why do you want to do that?
To go from a "foreach" loop to a "for" loop, change
foreach my $item (...list...) { ... }
to
my @list = (...list...); for my $i (0..$#list) { my $item = $list[$i]; ... }
In reply to Re^3: foreach to for (related to my last question)
by ikegami
in thread foreach to for (related to my last question)
by tricolaire
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |