Hello all,
I'm facing a unique problem. Well, the background: I need to convert a date and time string (in format <yyyy-mm-dd hh:mm:ss>) into seconds since epoch, and perform some mathematical operation on it. After googling, I decided to use Date::Parse's str2time() function. I downloaded the module from CPAN and even wrote an extememely simple test program to test it. It is here:
#!/usr/bin/perl
use strict;
use warnings;
use Date::Parse;
print str2time("2011-03-18 02:39:04") . "\n";
print str2time("1970-01-01 00:00:10") . "\n";
print str2time("2012-01-05 14:23:09") . "\n";
exit;
Happy with it, I proceeded to use it in my actual code, which is a class file. In it, however, I get an error saying str2time() is not defined! Below is my class:
##########
use strict;
use warnings;
use Date::Parse;
<some more code here>
$dashboardAlarmStartTime = $dashboardAlarm->startTime;
print "dashboardAlarmStartTime: " . $dashboardAlarmStartTime . "\n";
$maxDashboardAlarmForGroupStartTime = $maxDashboardAlarmForGroup->star
+tTime;
print "maxDashboardAlarmForGroupStartTime: " . $maxDashboardAlarmForGr
+oupStartTime . "\n";
my $timeDiff = str2time($dashboardAlarmStartTime) - str2time($maxDashb
+oardAlarmForGroupStartTime);
print "timeDiff: " . $timeDiff . "\n";
I get an error at the line my $timeDiff = str2time(). Where am I going wrong?
I tried the following to verify that the module is indeed present:
perl -MDate::Parse -le 'print $INC{"Date/Parse.pm"}'
And the output was: /usr/lib/perl5/site_perl/5.8.8/Date/Parse.pm
Please help me out here, I'd really appreciate it.
Thanks!
Trupti
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.