I want calculate days, Date::Calc is a good choice.
After a list of tests, I drew a chain of dependences
Date::Calc =>
Bit::Vector
Carp::Clan => Test::Exception => Sub::Uplevel
Dowload all tar files at http://search.cpan.org/
The basic installation steps are
1 tarzxvf file.tar.gz
2 cd to folder
3 perl Makefile.PL
4 make
5 make test
6 make install
The order for installation is the reverse to the dependence chain, Sub::Uplevel, Test::Exception, Carp::Clan, Bit::Vector, then Date::Calc.
Sub::Uplevel is the first to be installed. Following first 5 steps, the last step 6, “make install’ need to be twisted.
I just copied lib/Sub to my local perl module folder
rsync -avl lib/Sub ~/perl_mod/
To install Test::Exception, do steps 1 and 2, add this line
use lib “$ENV{‘HOME’}/perl_mod”;
to Makefile.PL, just after line
use ExtUtils::MakeMaker;
then, complete steps 3 to 5, the test step may be fail, because Sub::Uplevel is not at the default location, don’t worry, just
rsync -avl lib/Test ~/perl_mod/
Repeat procedures for Carp::Clan and Bit::Vector, finally for Date::Calc
remember to call these locally installed modules, you must have one line at the beginning to your perl program
use lib “$ENV{‘HOME’}/perl_mod”;
After all of this, I want calculate how many days I have lived in this world.
My date of birth is 1897-12-21, Today is 2055-08-23
#!/bin/perl use lib "$ENV{'HOME'}/perl_mod"; use Date::Calc qw(:all); @birthdate = (1897, 12,21); @today = (2055,8,23); $days = Delta_Days(@birthdate,@today); ($y,$m,$d) = N_Delta_YMD (@birthdate,@today); printf "you have lived in this world for %d days or %d years, %d months and %d days\n", $days, $y,$m,$d; exit 0;
it said
you have lived in this world for 57588 days or 157 years, 8 months and 2 days