PERL MODULES
It is often the case with code, that a subroutine or function may need to be reused by a number of programs. In this situation, it would be easier to write the subroutine once and then call it from each program. A Perl module provides this capability.
A Perl module is a package stored in a single file. The Perl module has the same name as the package, but is given the extension .pm to denote a perl module.
Exporting Perl Module Symbols
A Perl module allows symbols such as a subroutine name or a variable name to be exported to the program that it is called by. The symbols are exported by means of the Perl Exporter module. Typically, the @ISA array is used too to check for the import method.
Installing a Perl Module.
- Determine which type of Perl module you require
- Go to www.cpan.org (The Comprehensive Perl Archive Network)
- Identify the relevant module and download the module
The Perl module will most likely be stored in a compressed tar format (tar.gz), so the module will need to be decompressed as follows:
>gunzip Perlmodulename.tar.gz
>tar -xvf Perlmodulename.tar |
Now the module is installed as follows:
>perl Makefile.PL >make
>make test
>make install |
Useful Perl Modules
- LWP
- The LWP, libwww-perl or Library for WWW access for Perl, provides a simple API to the world wide web via a collection of Perl modules. The most commonly used object in the LWP module is UserAgent, since UserAgent looks after low level communication and error handling. In order for LWP to be used for communication, a UserAgent object needs to be created. The class name for UserAgent is LWP::UserAgent, so UserAgent would be used as follows:
|
use LWP::UserAgent;
$user_agent_object = new LWP::UserAgent;
$user_agent_object->agent("AgentName/0.1 " . $user_agent_object->agent);
|
- CGI
- DBI
-