Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

As this is mostly static info (except for leap years), you might just want to use a simple lookup table.

my %period = ( Jan => ['01 Dec','31 Dec'], Feb => ['01 Jan','31 Jan'], Mar => ['01 Feb','28 Feb'], #... Dec => ['01 Nov','30 Nov'], ); my $curr_month = "Mar"; my $curr_year = 2010; my $p = $period{$curr_month}; print "$p->[0] $curr_year - $p->[1] $curr_year\n"; # 01 Feb 2010 - 2 +8 Feb 2010

To figure out when the "28 Feb" isn't correct, you could use one of the many date modules on CPAN (this is left as an exercise for... :).  Or simply hardcode a list of those years up until the time you'll retire ;)

Update: the following should also work for up to 2099

... my $p = $period{$curr_month}; if ($curr_month eq "Mar") { $p->[1] = '29 Feb' unless $curr_year % 4; } ...

In reply to Re: How to get last month date period by almut
in thread How to get last month date period by roborat

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (5)
    As of 2017-06-24 08:51 GMT
    Find Nodes?
      Voting Booth?
      How many monitors do you use while coding?

      Results (557 votes). Check out past polls.