1834251 Members
2663 Online
110066 Solutions
New Discussion

Perl Modules

 
SOLVED
Go to solution
Ragni Singh
Super Advisor

Perl Modules

Hey All,

How do I find out if the following perl modules are installed on my server. Modules are:
DBI
Net-Daemon
PlRPC

Thanks and any help is greatly appreciated.
6 REPLIES 6
Scott Corzine
Advisor
Solution

Re: Perl Modules

Hi-

The simple, brute force way to check that perl modules are correctly installed and loadable is to create a test script and try to use them:

#!/usr/bin/perl

use DBI;
use Net::Daemon; # I assume you want this
use PIRPC;

print "Ok\n";

or just:

perl -MDBI -MNet::Daemon -MPIRPC -e 'print "ok\n"'

I think the CPAN module may have some useful tools, and I'm sure there are more elegant ways to check. You can put the use statments in an eval { } block to trap exceptions.

-Scott-
Ralph Grothe
Honored Contributor

Re: Perl Modules

Hi,

the mentioned modules aren't those belonging to a usual standard installation.

Thus if they were installed "correctly", what I assume, the Perl MakeMaker module will install them under the sitelib subdir.

Though I could provide you with an ugly Perl one-liner to have Perl check if they are installed, I guess it would be easier to use a regular Unix find.

perl -V:installsitelib

will tell you the start directory from where to search.

All (CPAN) Perl modules have per convention to have filenames like

.pm

So to look for e.g. DBI.pm

find /opt/perl5/lib/site_perl -type f -name DBI.pm


On the other hand you can simply check the presence of a version No. as every CPAN module must define it.

e.g.

# perl -MDBI -e 'print "$DBI::VERSION\n"'
1.30

If it weren't installed you'd get an error message.
Madness, thy name is system administration
Ragni Singh
Super Advisor

Re: Perl Modules

What is the -M and -e option mean?
Ralph Grothe
Honored Contributor

Re: Perl Modules

If I had noticed that Scott already posted one working method I wouldn't have submitted my own.

But I'd like to add my suspicion that the suggested eval block wouldn't work because the use statement will be executed at compile time whereas a trapping of the eval block would happen at runtime.

But you could trap a require() of the module.

e.g.

eval { require SomeModule };
if ($@) {
warn "cannot load SomeModule";
}

If the required module is used the OO way it wouldn't matter because you don't need to import any variables or functions in your namespace, but use the OO interface's accessor methods instead.
Madness, thy name is system administration
H.Merijn Brand (procura
Honored Contributor

Re: Perl Modules

-M... is short for "use ...;"
-e... is the script to run (each -e represents a single perl line, don't forget the ;'s)

see 'man perlrun'

If you're looking for those modules to install DBD::Oracle, note that Net::Daemon and PlRPC are optional, and perl hes to be build `Oracle-Prepared', meaning that libs should start with '-lcl -lpthread':

d3:/wrk 106 > perl -V | grep libs=
libs=-lcl -lpthread -lnsl_s -lndbm -lgdbm -ldb -lmalloc -ldld -lm -lc -lndir -lcrypt -lsec
perllibs=-lcl -lpthread -lnsl_s -lmalloc -ldld -lm -lc -lndir -lcrypt -lsec
d3:/wrk 107 >

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Ralph Grothe
Honored Contributor

Re: Perl Modules

At the shell type

perldoc perlrun

or

man perlrun


The -M is another way of loading a module on the interpreter's invocation instead of saying "use" in a script.

The -e tells the Perl interpreter that the next string on the command line that follows is the script to be interpreted
(similar to grep, sed, awk)
Madness, thy name is system administration