[ABE.pm] arg isn't numeric?

Ricardo SIGNES rjbs-perl-abe at lists.manxome.org
Wed Feb 11 13:57:24 CST 2004


* Phil Lawrence <prlawrence at lehigh.edu> [2004-02-11T11:30:36]
> SOURCE:
> #!/usr/local/bin/perl
> use warnings;
> use diagnostics;
> use strict;
> 
> use POSIX;
> use Date::Calc qw( :all );

This is just a bit of evangelism, but: Do look at using DateTime!  It
does /everything/, and it has a reasonable interface for all of it.
Date::Calc, Time::Date, Date::Parse, Time::Local and so on all address
parts of the problem, but they're awkward to use.

http://datetime.perl.org/

> my $begin = shift();
> my $end   = shift();
> my $per   = shift();

Providing defaults would be nice:
 my $begin = shift || do { print "using default begin"; "2003-01-01" };

You could do some nice validation here, too.
 $begin = '2003-01-01' unless $begin =~ /^\d{4}-\d{2}-\d{2}$/;

There's probably a Regex::Common for iso dates.

> my $delta = Delta_Days( split('-',$begin), split('-',$end) );
> my $intrvl = ceil($delta / $per);
> 
> print "begin:  ", $begin, "\n";
> print "end:    ", $end, "\n";
> print "per:    ", $per, "\n";
> print "delta:  ", $delta, "\n";
> print "intrvl: ", $intrvl, "\n";

Prime candidate for a here-doc.

print <<EOH;
begin:  $begin
end:    $end
per:    $per
delta:  $delta
intrvl: $intrvl
EOH

...of course, as a throwaway, this doesn't matter so much, but good
idioms used always are a good habit.

-- 
rjbs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/abe-pm/attachments/20040211/d1629d88/attachment.bin


More information about the ABE-pm mailing list