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