I am trying a script to get the no. of days between now and a future date. I intend to run this script on AIX and linux from a common location. Now, I am using modules DateTime
for linux and Date::Calc
for AIX. For some reason, each doesn't work in the other OS.
So, I am writing an if statement and checking for OS. If it's AIX, I am using Date::Calc
or I am using DateTime
. Here's my code
#!/usr/bin/perl
use strict;
use warnings;
my $OS = `uname`;
if ( $OS=~/AIX/i ) {
use Date::Calc qw(Delta_Days);
my @today = (localtime)[5,4,3];
$today[0] += 1900;
$today[1]++;
my @end = (2015, 11, 12);
my $expiry = Delta_Days(@today, @end);
print "$expiry\n";
} else {
require DateTime;
my $exp = DateTime->new( year => 2015, month => 11, day => 12 );
my $now = DateTime->now;
my $diff = $now->delta_days($exp);
my $expiry = $diff->delta_days;
print $expiry,"\n";}
This scripts appears to be working fine in AIX when i use use Date::Calc
in the if
loop. But when i run this script in linux, it gives me an error saying can't locate Date/Calc pm in @INC
.
When i change it to require Date::Calc
in the if loop, it gives me an error can't locate Date::Calc pm in @INC
on the AIX server. And it's vice versa with the else
loop for Linux OS too.
How can i achieve common ground? For some reason, i can't install these modules in one server or the other.