Hi Monks,

I have a requirement to provide stats on the last 12 months from current day. I have an array of months so I would need to report out Oct 15', Nov 15', Dec 15', Jan 16' thru Sep 16' as the last column. Next month, the report would run on Oct, 1st and so the report would begin with Nov 15', Dec 15', Jan 16', etc...

My code is as follows

#!/usr/bin/perl use POSIX 'strftime'; use strict; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; my $curr_mth = sprintf "%2d", strftime('%m', $sec,$min,$hour,$mday,$mo +n,$year,$wday,$yday,$isdst); my @month_name = qw(January February March April May June July August +September October November December); while (<DATA>) { my %by_month = split ' ', $_; for my $m ( $curr_mth .. $#month_name) { if ( exists ( $by_month{$month_name[$m]} ) ) { print "$by_month{$month_name[$m]} EXISTS for $ +month_name[$m] Row $.\n"; } else { print "$by_month{$month_name[$m]} DOES NOT EXI +STS $month_name[$m] for row $.\n"; } } } __DATA__ February 1 March 5 July 4 August 5 October 7 January 3 March 4 April 6 May 5 June 7 July 8 August 10 September 4 Oc +tober 9 November 11 December 8 March 2 June 3 August 1 December 7

I have figured out how to start looping thru the Months array at October, but I can't figure out how to go past the end to September.

thanks very much for your time and effort and ideas.


In reply to 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.