Cirollo has asked for the wisdom of the Perl Monks concerning the following question:
Is there a better way to do this? Maybe through one of Perl's special variables? I thought about searching for the array index containing the current value (like, "what is the index of @array that contains $_"). Also, I'm not necessarily looking for a solution to give me a total end count of iterations, but more for telling me how many iterations I have gone through so I can say things like "print this line every 3rd time through the loop"$i = 0; foreach (@array) { # do stuff $i++; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Of foreach loops and counting
by eak (Monk) on Aug 09, 2000 at 19:42 UTC | |
by turnstep (Parson) on Aug 09, 2000 at 20:27 UTC | |
by Cirollo (Friar) on Aug 09, 2000 at 19:44 UTC | |
|
(jeffa) Re: Of foreach loops and counting
by jeffa (Bishop) on Aug 09, 2000 at 19:47 UTC | |
by KM (Priest) on Aug 09, 2000 at 20:18 UTC | |
by eak (Monk) on Aug 09, 2000 at 20:08 UTC | |
|
Re: Of foreach loops and counting
by ferrency (Deacon) on Aug 09, 2000 at 20:18 UTC | |
by KM (Priest) on Aug 09, 2000 at 20:29 UTC |