2

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';
JB.
  • 40,344
  • 12
  • 79
  • 106
maanoor99
  • 131
  • 2
  • 4
  • 15
  • 2
    From the [Stack Overflow Perl FAQ](http://stackoverflow.com/questions/tagged/perl?sort=faq): [What's the easiest way to install a missing Perl module?](http://stackoverflow.com/questions/65865/whats-the-easiest-way-to-install-a-missing-perl-module) – daxim Jul 19 '12 at 17:25
  • This is a core module - it should be installed with Perl. – Gert van den Berg May 14 '18 at 15:51

1 Answers1

7

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
ikegami
  • 367,544
  • 15
  • 269
  • 518
  • @jimtut, Thank's. Its now fixed. (*wink*) – ikegami Jul 19 '12 at 19:20
  • One more thing, in the Perl program, you have to manually tell it where to look. So I had to put this code line: `use lib "/home/el/perl5/lib/perl5/x86_64-linux-thread-multi";` before the invocation of: `use Time::Piece;` in my perl program. I was able to find which path to use by running the command: `locate Piece.pm` – Eric Leschinski Dec 17 '12 at 22:49
  • @Eric Leschinski, Your comment has nothing to do with this thread. You apparently installed a module into the non-default directory (and thus had to tell Perl where to look for it), but that's not what the OP is doing. – ikegami Dec 17 '12 at 23:09
  • I understand now. The command you provided `/usr/bin/perl -MCPAN -e install Time::Piece` picks the wrong default installation directory and my perl couldn't find it. The user has to install it in the right place or else perl won't find it. – Eric Leschinski Dec 17 '12 at 23:19
  • I had to install it in this format `perl -MCPAN -e 'install Time::Piece'` , otherwise it did not somehow work for me, I also had to install gcc `yum install gcc` – FantomX1 Sep 23 '20 at 16:04