cannot run perl program: Can't locate Time/Piece.pm in @INC with perl5.8.4 and Can't locate DBI.pm in @INC with perl 5.12.3

maanoor99 picture maanoor99 · Jul 19, 2012 · Viewed 14k times · Source

I have Solaris 10,i am trying to run a Perl program.

I have two perl versions installed:

/usr/bin/perl of version 5.8.4

and

/usr/local/bin/perl of version 5.12.3

I have installed the DBI package (it got installed here, /usr/perl5/site_perl/5.8.4/sun4-solaris-64int/auto/DBI/.packlist),the problem I get by executing the Perl program with different perl version is (In ubuntu its working fine).

bash-3.00# perl temp.pl
Can't locate Time/Piece.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    
temp.pl line 4.
BEGIN failed--compilation aborted at temp.pl line 4.

bash-3.00# /usr/local/bin/perl temp.pl
Can't locate DBI.pm in @INC (@INC contains: /usr/local/lib/perl5/site_perl/5.12.3 
/sun4-solaris /usr/local/lib/perl5/site_perl/5.12.3 /usr/local/lib/perl5/5.12.3/sun4- 
solaris /usr/local/lib/perl5/5.12.3 /usr/local/lib/perl5/site_perl .) at temp.pl line5.
BEGIN failed--compilation aborted at temp.pl line 5.

I have tried hell lot of ways but not getting how to run my Perl program on solaris. Could anybody help please.

Below is my program. In fact it was redefined by @Borodin. Thanks a lot to him.

use strict;
use warnings;

use Time::Piece;
use DBI;

open my $log, '<', '/opt/testlogs/test.log' or die "Unable to open log file: $!";

my ( $count_start, $count_interim, $count_stop ) = ( 0, 0, 0 );

while (<$log>) {

    if (/server start/) {
        $count_start++;
    }
    elsif (/server interim-update/) {
        $count_interim++;
    }
    elsif (/server stop/) {
        $count_stop++;
    }
}

print <<END;
Start:   $count_start
Interim: $count_interim
Stop:    $count_stop
END

print localtime->strftime("%b %e %H:%M:%S"), "\n";

my $dbh = DBI->connect( "DBI:Pg:dbname=postgres;host=localhost", "postgres", "postgres", { 'RaiseError' => 1 } );

my $rows = $dbh->do(
    "insert into radius (server_start, server_stop, server_interim)
       Values ($count_start, $count_stop, $count_interim)"
);

printf "%d %s affected\n", $rows, $rows == 1 ? 'row' : 'rows';

Answer

ikegami picture ikegami · Jul 19, 2012

You don't have Time::Piece installed for /usr/bin/perl, so install it.

/usr/bin/perl -MCPAN -e install Time::Piece

You don't have DBI installed for /usr/local/bin/perl, so install it.

/usr/local/bin/perl -MCPAN -e install DBI