I'm not entirely sure if this is what you are trying to do... However, if all you need to do is loop through an
array processing $N elements at a time, wouldn't it be easier to just take some slices with calculated indices?
#!/usr/bin/perl -wT
use strict;
my @a = (1..16); # test array
my $atatime = 3; # number of elements to loop over
for my $i (0..$#a/$atatime) { # loop through @a/$atatime times
my $min = $i*$atatime; # index of low element
my $max = $min+$atatime-1; # index of high element
$max = $#a if $max > $#a; # make sure we don't fall off the end
print join(", ", @a[$min..$max]),"\n"; # do something with our slic
+e
}
# Verify that we haven't munged our values
print "\nStill There: ", join(' ',@a), "\n";
=output
1, 2, 3
4, 5, 6
7, 8, 9
10, 11, 12
13, 14, 15
16
Still There: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Perhaps I don't understand what that nested while loop is
demonstrating in your sample code....
-Blake
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.