3

while running script i am getting below error:

Can't locate DateTime.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/ve

my code is :

#!/usr/bin/perl

use DBI;
use POSIX qw(strftime);
use DateTime;

my $dbh = DBI->connect(
    "dbi:mysql:dbname=agilefant-test",
   "agilefant-test",
    "Agilefant-test",
    { RaiseError => 1 },
) or die $DBI::errstr;

my $datestring = strftime "%Y %m %d %X", gmtime;
my $fourteen_days_from_now = $datestring->add(days =>14);

my $sth = $dbh->prepare("Insert into backlogs (backlogtype, id, description, name, backlogSize, baselineLoad, endDate, readonlyToken, startDate, rank, status, parent_id)
values ('Project' , '200', 'Sanchit Testing', 'Maintenance agilefant', NULL, NULL, ('$fourteen_days_from_now'), NULL, ('$datestring'), NULL, NULL, '34')");
$sth->execute() or die $DBI::errstr;
$sth->finish();

As from previous questions it different coz i cant upgrade my system as i dont have rights and also and i want to set End Date as after 14 days from current date. So need help for that also.

samio peter
  • 191
  • 2
  • 2
  • 8
  • 1
    So [install](http://www.cpan.org/modules/INSTALL.html) it. (You might want to [upgrade](http://perlbrew.pl/) from Perl 5.8 to one that is supported while you're at it. Perl 5.18 is the current stable, you're 5 major versions behind.) – Quentin Dec 11 '13 at 11:41
  • any other option because i cant upgrade it – samio peter Dec 11 '13 at 11:43
  • upgrading perl would not get you DateTime; DateTime is not included with the perl core, you must install it from CPAN (or whatever packaging system your os provides, which likely has it available) – ysth Dec 11 '13 at 11:58

3 Answers3

1

If you're on a system which you can't apply upgrades to, you should consider perlbrew. It handles all perl administration locally for the current user. i.e. you don't need admin rights.

ldx
  • 2,536
  • 2
  • 18
  • 27
1

You can use Time::Piece and Time::Seconds to add days to a date, and it also has the POSIX strftime. Also, they are core modules in Perl since v5.9.5.

use strict;
use warnings;
use Time::Piece;
use Time::Seconds;

my $t = localtime;
$t += ONE_DAY * 14;
print $t->strftime('%Y %m %d %X');
TLP
  • 66,756
  • 10
  • 92
  • 149
  • @ysth, Suprisingly, this actually works because Time::Piece overrides `localtime` to return an object with overloaded operators. – ikegami Dec 11 '13 at 13:43
  • @ikegami You're right, there's apparently more that goes on under the hood than meets the eye. Is there a good test case for date math to try this out? – TLP Dec 11 '13 at 14:03
  • ah, never mind, then. ssorry – ysth Dec 11 '13 at 15:11
  • For me POSIX strftime is working okay and related to Datetime.pm or Time.pm related not working on my system and i dont have permission to upgrade. I used perl -MPOSIX -e '$t = strftime "%Y%m%d", localtime(time() + 14 * 24 * 3600); print $t'. this is also have problem as Not all days have 24*3600 seconds. I am finding any other solution which gives me exact 14 days from todays date in end date?? – samio peter Dec 12 '13 at 05:39
  • @sammy, You don't need any special permissions to install modules. – ikegami Dec 12 '13 at 05:56
  • @ikegami I have tried to install by different suggestions but getting error – samio peter Dec 12 '13 at 06:45
  • @sammy Did you follow the link to the question above: http://stackoverflow.com/questions/65865/whats-the-easiest-way-to-install-a-missing-perl-module – TLP Dec 12 '13 at 11:32
  • Saying naught but "getting error" in a comment is a not good way to get help. – ikegami Dec 12 '13 at 13:38
0

I think the best solution is to install the missing module.

If you can't install it, according your code, maybe you just want get the date string of 14 days after today? You can compute it by your self with time.

just try this:

perl -MPOSIX -e '$t = strftime "%Y%m%d", localtime(time() + 14 * 24 * 3600); print $t'
ikegami
  • 367,544
  • 15
  • 269
  • 518
akawhy
  • 1,558
  • 1
  • 11
  • 18
  • with the solution you provided i am getting only one date after if today 11-12 then i get 12-12....I want 14 days after..... – samio peter Dec 11 '13 at 12:15
  • Not all days have 24*3600 seconds. In addition to giving the date 14 days from now as desired, your code can give the date 13 days from now, and it can give the date 15 days from now. – ikegami Dec 11 '13 at 13:42
  • For me POSIX strftime is working okay and related to Datetime.pm or Time.pm related not working on my system and i dont have permission to upgrade. I used perl -MPOSIX -e '$t = strftime "%Y%m%d", localtime(time() + 14 * 24 * 3600); print $t'. this is also have problem as Not all days have 24*3600 seconds. I am finding any other solution which gives me exact 14 days from todays date in end date?? – samio peter Dec 12 '13 at 05:39