Chapter 32 Perl modules

32.1 What is a Perl module

Perl modules are a set of related functions in a library file. They are specifically designed to be reusable by other modules or programs. There are more than 100,000 modules ready for you to use on the Comprehensive Perl Archive Network.

Most Perl modules are written in Perl, some use XS (they are written in C) so require a C compiler. Modules may have dependencies on other modules (almost always on CPAN) and cannot be installed without them (or without a specific version of them). Many modules on CPAN now require a recent version of Perl (version 5.8 or above).

The reason that we need to use Perl module is Perl module can largely reduce our coding work.

32.2 How to install a Perl module

Here we’ll only discuss how to install Perl module in Linux system. The easies way I think is to use cpanm.

Here is how you can do this. First go to webpage and download the cpanm source code.

## Web link:https://raw.githubusercontent.com/miyagawa/cpanminus/master/cpanm

chmod 755 cpanm

./cpanm Bio::Seq

NOTE

Possible problem when using cpanm

You may encouter the following error message. This is a bug from Perl. You cna run yum install perl-CPAN resolved the issue.

Here is the ERROR MESSAGE:

! ! Can’t write to /usr/local/share/perl5 and /usr/local/bin: Installing modules to /home/xie186/perl5 ! To turn off this warning, you have to do one of the following: ! - run me as a root or with –sudo option (to install to /usr/local/share/perl5 and /usr/local/bin) ! - Configure local::lib in your existing shell to set PERL_MM_OPT etc. ! - Install local::lib by running the following commands ! ! cpanm –local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib) ! –> Working on Bio::Seq Fetching http://www.cpan.org/authors/id/C/CJ/CJFIELDS/BioPerl-1.007001.tar.gz … OK ==> Found dependencies: Module::Build, ExtUtils::Install –> Working on Module::Build Fetching http://www.cpan.org/authors/id/L/LE/LEONT/Module-Build-0.4222.tar.gz … OK ==> Found dependencies: Module::Metadata, version, CPAN::Meta, Perl::OSType –> Working on Module::Metadata Fetching http://www.cpan.org/authors/id/E/ET/ETHER/Module-Metadata-1.000033.tar.gz … OK ==> Found dependencies: ExtUtils::MakeMaker –> Working on ExtUtils::MakeMaker Fetching http://www.cpan.org/authors/id/B/BI/BINGOS/ExtUtils-MakeMaker-7.26.tar.gz … OK Configuring ExtUtils-MakeMaker-7.26 … OK Can’t locate ExtUtils/Manifest.pm in (INC?) ((INC?) contains: FatPacked::26160008=HASH(0x18f2b88) /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at ./cpanm line 132.

32.3 How to use a Perl module

32.4 How to use BioPerl module

32.5 How to write a module