views:

3482

answers:

6

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. :(

+4  A: 

You're missing Date::Parse on the Solaris box. The ideal solution would be to install this on the system, but since you can't, you can just go ahead and install the module into your home directory: http://servers.digitaldaze.com/extensions/perl/modules.html

Don Werve
This script needs to be shipped to a customer who runs Solaris 10!. So asking him to install the module is definitely not an option. :(
pavanlimo
Then cut-n-paste, obviously.
jrockway
+2  A: 

Are you sure that's the right error message? Date::Parse is an entirely separate module from Time::ParseDate. They provide similar functionality, but don't use each other.

You can use Module::CoreList to get a list of the modules that shipped with 5.8.8. I don't know if Solaris 10 included any additional modules.

You might have to copy the guts out of a suitable module and paste it into your script. (Remember that a Perl file may have multiple package statements.)

cjm
I was basically trying solutions provided herehttp://stackoverflow.com/questions/411740/how-can-i-parse-dates-and-convert-time-zones-in-perlI was getting similar error messages of the module not being present and hence may be pasted the wrong one here. Sorry bout that. But the problem remains :|
pavanlimo
+4  A: 

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?"

mctylr
+2  A: 

You should be able to do this with Time::Piece which is core on Perl 5.10 (correction here: it's not core in 5.8). Here's an example from my machine. See man strftime, man strptime and perldoc Time::Piece. In the Time::Piece docs, you want to check the section Date Parsing. (The conversion details may vary on a Solaris machine. I'm on OS X right now at work.)

#!/usr/bin/env perl
use strict;
use warnings;
use Time::Piece;

my $date = Time::Piece->strptime("Tue Apr 7 12:46:59 2009",
  "%a %b %e %H:%M:%S %Y");
my $epoch_date = $date->epoch;

print "$epoch_date\n";

Edit: The parser chokes on CDT (%Z doesn't appear to recognize it), so you may need to do this in two steps. The following works for me:

my $string = "Mon Mar 27 05:54:08 CDT 2009";
$string =~ s/CDT/-0500/; # Replace timezone with offset from UTC
my $date = Time::Piece->strptime($string, "%a %b %e %H:%M:%S %z %Y");
my $epoch_date = $date->epoch;

print "$epoch_date\n";

However, now we have the additional problem of CDT => -0500 versus CST => -0600. I officially hate daylight savings.

Telemachus
pavanlimo
According to Module::CoreList, Time::Piece did not become a core module until 5.9.5, which was part of the development series leading up to Perl 5.10. It works with 5.8, but it didn't ship with it. (OS X might have included it as an extra.)
cjm
No, actually, you're right. I was not careful enough about which core modules I was checking. It's not present in 5.8. Apologies for the mistake.
Telemachus
+3  A: 

Since you need to ship the program to a customer who will not install modules for you, you will need to use PAR::Packer to create a native executable that contains all of your dependencies (or use only Core Modules).

Chas. Owens
A: 

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

Silly question, but what is the source of the input date string? If the string is fetched from the system your code can be a lot more simple.

converter42