[ABE.pm] making things more perlish
Jim Eshleman
jce0 at Lehigh.EDU
Fri Jan 7 22:30:10 PST 2005
Long ago I decided to use Date::Calc for these kinds of things, so here
is how I would do it. I know it doesn't really answer your question but
thought it may be of some use...
#!/usr/bin/perl -w
use Date::Calc qw(:all);
use strict;
print ldopm() . "\n";
print ldopm("20041231") . "\n";
print ldopm(ldopm()) . "\n";
print ldopm("20050101") . "\n";
print ldopm("20040301") . "\n";
print ldopm("20030301") . "\n";
print ldopm("00000000") . "\n";
sub ldopm {
# Get the last day of the previous month
my $ymdstr = shift;
my @ymd;
if ($ymdstr) {
@ymd = $ymdstr =~ /(\d\d\d\d)(\d\d)(\d\d)/;
check_date(@ymd) or die "ldopm: invalid date '$ymdstr'\n";
} else {
@ymd = Today();
}
return sprintf "%04d%02d%02d", Add_Delta_Days(@ymd, -$ymd[2]);
}
should produce:
$ ./ldopm.pl
20041231
20041130
20041130
20041231
20040229
20030228
ldopm: invalid date '00000000'
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
Url : http://mail.pm.org/pipermail/abe-pm/attachments/20050108/ed7c49f4/signature.bin
More information about the ABE-pm
mailing list