The following subroutine isn't a module, but it should work fine pasted anywhere in your code.
use strict;
use warnings;
print monthdays('Jan',1998), "\n";
print monthdays('FEB',1999), "\n";
print monthdays('FeB',2000), "\n";
print monthdays(2,2100), "\n";
# Takes two arguments, both required:
# Month - can be either numerical in the range 0-11, or alphabetic,
# ignoring case.
# Year - 4-digit format recommended.
BEGIN {
my %md_mon = ('JAN',1,'FEB',2,'MAR',3,'APR',4,'MAY',5,'JUN',6,
'JUL',7,'AUG',8,'SEP',9,'OCT',10,'NOV',11,'DEC',12);
my @md_mon = (0,31,28,31,30,31,30,31,31,30,31,30,31);
sub monthdays {
my ($m, $y) = @_;
$m = $md_mon{uc($m)} if $m =~ /[a-zA-Z]/;
my $d = $md_mon[$m];
$d++ if $m == 2 && $y % 4 == 0 && ($y % 100 != 0 || $y % 400 =
+= 0);
return $d;
}
}
|