Saturday, 5 July 2014

PS_10_Perl - Modules

Modules

Namespaces and Packages:
Namespaces store identifiers for a package, including variables, subroutines, filehandles, and formats, so that they are distinct from those of another package. The default namespace for the body of any Perl program is main. You can refer to the variables from another package by “qualifying” them with the package name. To do this, place the name of the package followed by two colons before the identifier’s name:
$Package::varname
If the package name is null, the main package is assumed.

Modules:
Modules are Perl’s answer to software packages. They extend the functionality of core Perl with additional compiled code and scripts. To make use of a package (if it’s installed on your system), call the use function:
use CGI;

This will pull in the module’s subroutines and variables at compile time. use can also take a list of strings naming entities to be imported from the module:
use Module qw(const1 const2 func1 func2);

Perl looks for modules by searching the directories listed in @INC. Modules can be obtained from the Comprehensive Perl Archive Network (CPAN) at

http://www.cpan.org/modules/

or from the ActiveState site:

http://www.ActiveState.com/packages/zips/

To install modules under UNIX, unarchive the file containing the package, change into its directory and type:
perl Makefile.PL
make
make install

On Windows, the ActivePerl distribution makes use of the “Perl Package Manager” to install/remove/update packages. To install a package, run ppm on the .ppd file associated with the module:
ppm install module.ppd

No comments :

Post a Comment