in reply to Re: How to iterate thru entire array with start point other than beginning
in thread How to iterate thru entire array with start point other than beginning
The only objection I would make to the array slice approaches of GrandFather here or soonix here (++ to both by the way) is that they start to produce strange results for $startMonthIdx values outside the 0 .. @month_name range. This may not be a real problem since one may never endeavor to venture outside this range.
The attraction for me of the modulo-@month_name approach is that it gives sensible results for any weird positive or negative range whatever. I would prefer to impose any range limits in a separate step and then just reliably handle whatever range emerged from the validation process.
c:\@Work\Perl\monks>perl -wMstrict -le "my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); ;; for my $offset (-25 .. -11) { printf 'offset %3d: ', $offset; my @sel = map $months[ ($_ + $offset) % @months ], -109 .. -95; printf qq{@sel}; print ''; } " offset -25: Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Ja +n offset -24: Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan Fe +b offset -23: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan Feb Ma +r offset -22: Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan Feb Mar Ap +r offset -21: Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan Feb Mar Apr Ma +y offset -20: Apr May Jun Jul Aug Sep Oct Nov Dec Jan Feb Mar Apr May Ju +n offset -19: May Jun Jul Aug Sep Oct Nov Dec Jan Feb Mar Apr May Jun Ju +l offset -18: Jun Jul Aug Sep Oct Nov Dec Jan Feb Mar Apr May Jun Jul Au +g offset -17: Jul Aug Sep Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Se +p offset -16: Aug Sep Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oc +t offset -15: Sep Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct No +v offset -14: Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov De +c offset -13: Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Ja +n offset -12: Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan Fe +b offset -11: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan Feb Ma +r
Give a man a fish: <%-{-{-{-<
|
|---|