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:  <%-{-{-{-<


In reply to Re^2: How to iterate thru entire array with start point other than beginning by AnomalousMonk
in thread How to iterate thru entire array with start point other than beginning by dirtdog

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.