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

comment on

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

Here's my refactored version of your demonstration script:

use strict; use warnings; use Time::Piece; my $year = shift @ARGV || 2014; my $p = '%Y/%m/%d'; # strptime() format my $f = '%a %b %d %Y'; # strftime() format my $t = Time::Piece->new(); for my $month (1 .. 12) { # Compute the last day of the month... my $monthLastDay = $t->strptime("$year/$month/1", $p)->month_last_day(); # Compute the day of the week of the last day of the month (Sunday + = 1)... my $weekDay = $t->strptime("$year/$month/$monthLastDay", $p)->wday(); # Compute the day of the last Friday of the month (Friday = 6)... my $lastFridayDate = $monthLastDay - (($weekDay - 6) % 7); # Compute the last Friday of the month... my $lastFriday = $t->strptime("$year/$month/$lastFridayDate", $p)->strftime($ +f); print "$lastFriday\n"; } exit 0; __END__ Fri Jan 31 2014 Fri Feb 28 2014 Fri Mar 28 2014 Fri Apr 25 2014 Fri May 30 2014 Fri Jun 27 2014 Fri Jul 25 2014 Fri Aug 29 2014 Fri Sep 26 2014 Fri Oct 31 2014 Fri Nov 28 2014 Fri Dec 26 2014

In reply to Re^2: Gettting the last Friday of every month using Time::Piece by Jim
in thread Gettting the last Friday of every month using Time::Piece by Anonymous Monk

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 the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (7)
    As of 2021-04-13 16:51 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found