For a pure perl solution I use my mapn function to iterate lists in groups. You can use within a for loop also, though it requires array ref syntax to access the elements of the group. I find this a bonus as it means I can use the flexibility of array slices:

#! perl -slw use strict; sub mapn (&$@) { my( $code, $n, ) = ( shift, shift ); map { $code->( @_[ $_ .. $_ + $n -1 ] ); } map $n * $_, 0 .. ( $#_ / $n ); } use constant { A => 0, B => 1, C =>2, D => 3, E => 4 }; for my $iters ( mapn{ \@_ } 5, 0 .. 99 ) { printf "%d %d %d %d\n", @{ $iters }[ A, C, E, D ]; } __END__ C:\test>junk 0 2 4 3 5 7 9 8 10 12 14 13 15 17 19 18 20 22 24 23 25 27 29 28 30 32 34 33 35 37 39 38 40 42 44 43 45 47 49 48 50 52 54 53 55 57 59 58 60 62 64 63 65 67 69 68 70 72 74 73 75 77 79 78 80 82 84 83 85 87 89 88 90 92 94 93 95 97 99 98

The constants aren't necessary, but allow for clarity through symbolic names.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: best way to implement multiple foreach iterator variables? by BrowserUk
in thread best way to implement multiple foreach iterator variables? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.