use strict;
use warnings;
use Time::Piece;
use Time::Seconds;
my $t = Time::Piece->new();
my $year = $ARGV[ 0 ] || 2014;
foreach my $month ( 1 .. 12 ) {
my $tdates = $t->strptime("$year/$month/1", '%Y/%m/%d');
my $day_of_month = $tdates->month_last_day();
$tdates = $t->strptime("$year/$month/$day_of_month", '%Y/%m/%d');
while ($tdates->wdayname ne 'Fri') {
$tdates -= ONE_DAY;
}
printf "Last Friday of Month %02d is %s\n", $month, $tdates->ymd()
+;
}
__END__
Last Friday of Month 01 is 2014-01-31
Last Friday of Month 02 is 2014-02-28
Last Friday of Month 03 is 2014-03-28
Last Friday of Month 04 is 2014-04-25
Last Friday of Month 05 is 2014-05-30
Last Friday of Month 06 is 2014-06-27
Last Friday of Month 07 is 2014-07-25
Last Friday of Month 08 is 2014-08-29
Last Friday of Month 09 is 2014-09-26
Last Friday of Month 10 is 2014-10-31
Last Friday of Month 11 is 2014-11-28
Last Friday of Month 12 is 2014-12-26
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|