quick tip: how to check if perl module is present?


A. Checking if Perl Module is Installed

This is important on checking if a given perl module is already installed or not.

Code:

#perl -MModule::Name -e 1

example:
#

if present, no errors appeared:
[root@darwin ~]# perl -MNet::SNMP -e 1

without:

[root@darwin ~]# perl -MNet::Telnet -e 1

Can’t locate Net/Telnet.pm in @INC (@INC contains: /usr/lib/perl5/5.10.0/i386-linux-thread-multi /usr/lib/perl5/5.10.0 /usr/local/lib/perl5/site_perl/5.10.0/i386-linux-thread-multi /usr/local/lib/perl5/site_perl/5.10.0 /usr/lib/perl5/vendor_perl/5.10.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.10.0 /usr/lib/perl5/vendor_perl /usr/local/lib/perl5/site_perl/5.10.0/i386-linux-thread-multi /usr/local/lib/perl5/site_perl/5.10.0 /usr/local/lib/perl5/site_perl /usr/lib/perl5/site_perl .).
BEGIN failed–compilation aborted.

B. Check if the documentation of a perl module is installed.
Code:
perldoc Module::Name
e.g.

# perldoc Net::SNMP

Net::SNMP(3) User Contributed Perl Documentation Net::SNMP(3)
NAME
Net::SNMP – Object oriented interface to SNMP

without:

[root@darwin ~]# perldoc Net::Telnet

No documentation found for “Net::Telnet”.

INSTALLING PERL MODULES

1. via CPAN

(+) Open CPAN shell:

# perl -MCPAN -e shell

(+) To reconfigure the shell if needed.

cpan>o conf init

(+) Install an available module.

cpan> install Module::Name

# Force install if test fails.

cpan> force install Module::Name

2. Manual
Search and download the file in http://search.cpan.org
e.g. Time::HiRes

searching in cpan

searching in cpan

#wget http://search.cpan.org/CPAN/authors/id/J/JH/JHI/Time-HiRes-1.9719.tar.gz
#tar zxvf Time-HiRes-1.9719.tar.gz
# perl Makefile.PL
# make
# make test
# make install

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: