How to Add Modules to Perl
Perl has an immense collection of user-created modules known as the "Comprehensive Perl Archive Network," or CPAN for short. These modules are added to your Perl environment with the CPAN command. There are different ways to search for and add modules, depending on the type of system you are running.
Instructions
-
Add Modules to Perl on Unix
-
1
Decompress the module by typing the gzip command on the command line:
" gzip -d yourmodule.tar.gz" -
2
Unpack the decompressed file, using the tar command:
"tar -xof yourmodule.tar" -
-
3
Build the module, if necessary, and install it in the directory you have created. You will have to be root or have the appropriate permissions to add a module to your Perl library:
"perl Makefile.PL
make
make test""make install"
Add Modules to Perl on Windows
-
4
Type "ppm" at the DOS prompt to access the ActiveState Perl Package Manager command-line tool.
-
5
Search for a module, using the search function at the Pp.m.> prompt. This example searches for modules related to money:
"search Money" -
6
Install the module, using the install command. Perl Package Manager will then download and install the module:
"install Money-modules"
Add Modules to Perl Using CPAN
-
7
Start the CPAN command. Perl comes with CPAN already, so simply start the CPAN command-line program with the command "cpan". If you're using Linux, you might have to start CPAN under root or with sudo.
-
8
Search the CPAN browsable database by query to find a module and/or script to install (see Resources below). Browse by category or author by using the "Category" or "Authors" tabs.
-
9
Install the module using a single command from the cpan command-line. This example installs the "Roman" module for converting numbers to and from Roman numerals:
"install Roman" -
10
Use the module. Using the module is easy now that it's installed. Simply use the "Use" keyword to import the module, then use any functions or classes the module provides:
"use Roman;"
-
1
Tips & Warnings
Use patience when installing modules, as it takes a fair amount of time. CPAN will download the module from one of the mirrors, unpack it and install it, along with any modules that depend on the module you're installing. Also, if your system has the make command, CPAN will perform any unit tests that come with the module. These tests can also take some time, but they assure the module works correctly.