Questions And Answers

More Tutorials


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:

If the package name is null, the main package is assumed.

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

or from the ActiveState site:

To install modules under UNIX, unarchive the file containing the package, change into its directory and type:
perl Makefile.PL
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


In this page (written and validated by ) you learned about Perl Modules . What's Next? If you are interested in completing Perl tutorial, your next topic will be learning about: Perl Object oriented.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.