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.
|