Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a date into epoch time in Perl?

Solaris 10 doesn't seem to like me a lot. I am trying to run a simple script to accept date and return epoch of that date:

#!/usr/bin/perl -w
use strict;
use Time::ParseDate;

my $date1 = "Mon Mar 27 05:54:08 CDT 2009";

#Convert to seconds since start of epoch
my $time1 = parsedate($date1);
print $time1;

Works perfectly fine on RHEL box, but gets screwed on Solaris(both have 5.8.8 Perl), giving the following error message.

Can't locate Date/Parse.pm in @INC (@INC contains: /usr/perl5/5.8.4/lib/sun4-solaris-64int /usr/perl5/5.8.4/lib /usr/perl5/site_perl/5.8.4/sun4-solaris-64int /usr/perl5/site_perl/5.8.4 /usr/perl5/site_perl /usr/perl5/vendor_perl/5.8.4/sun4-solaris-64int /usr/perl5/vendor_perl/5.8.4 /usr/perl5/vendor_perl .) at try1.pl line 3. BEGIN failed--compilation aborted at try1.pl line 3.

Whats wrong here?.. how to correct this?.

Oh.. almost forgot, I cannot alter/install/modify anything on this Solaris box, this script needs to be shipped to a customer who runs Solaris 10!. So asking him to install a module is definitely not an option. :(

like image 390
pavanlimo Avatar asked Dec 09 '22 21:12

pavanlimo


1 Answers

The error message says it cannot find the module Date::Parse in your Perl library include path (@INC).

The module is available from CPAN (Comprehensive Perl Archive Network). If you need a Perl module that is not included in the base install, typically (>90%) it is available from CPAN, the de facto Perl module archive site.

Your question is addressed with the CPAN module (the CPAN module is used to retrieve modules from CPAN) documentation. I suggest starting with FAQ question 5, "I am not root, how can I install a module in a personal directory?"

like image 144
mctylr Avatar answered Jan 02 '23 05:01

mctylr