Once you have installed Perl, you can use the CPAN extension to install any other extensions or modules that you may need for development. The CPAN extension automates the process of retrieving the necessary source code from The Comprehensive Perl Archive Network, uncompressing, configuring, and building it into an extension. Fortunately, the CPAN extension is installed by default with Perl, so you don t have to spend time tracking down and building this valuable extension.
Suppose, for example, you need an extension to send e-mail from a Perl program. Your first step should be to go to CPAN and check to see if such an extension exists. You can do this by pointing your browser to http://search.cpan.org and entering Send Mail into the search field. You will see a number of e-mail related modules that match the criteria. Traverse down the list and you should see the Mail::Send extension that was briefly discussed earlier; the Mail::Send extension is actually part of the MailTools package, as you will see in the installation example that follows . Now, log in as root and use the CPAN extension to install the module:
# perl -MCPAN -e shell /usr/lib/perl5/5.8.3/CPAN/Config.pm initialized. CPAN is the world-wide archive of perl resources. It consists of about 100 sites that all replicate the same contents all around the globe. Many countries have at least one CPAN site already. The resources found on CPAN are easily accessible with the CPAN.pm module. If you want to use CPAN.pm, you have to configure it properly. ...
The -M switch asks Perl to load the CPAN extension, which implements, among other things, a function called shell . This function is responsible for providing a user interface, or a shell, where you can search for and install modules. You can execute this function by using the -e switch. As you will see later, you can also use this switch to execute arbitrary pieces of Perl code from the command line.
The first time you use the CPAN shell, it will ask you a number of questions, including where to store the sources and what CPAN mirror to use. You should be able to simply choose the default answers and continue. Once inside the shell, use the install command with the name of the extension to start the process of installation:
cpan> install Mail::Send CPAN: Storable loaded ok CPAN: LWP::UserAgent loaded ok Fetching with LWP: ftp://mirrors.kernel.org/pub/CPAN/authors/01mailrc.txt.gz Going to read /root/.cpan/sources/authors/01mailrc.txt.gz Fetching with LWP: ftp://mirrors.kernel.org/pub/CPAN/modules/02packages.details.txt.gz ... Running make for M/MA/MARKOV/MailTools-1.61.tar.gz Fetching with LWP: ftp://mirrors.kernel.org/pub/CPAN/authors/id/M/MA/MARKOV/MailTools-1.61.tar.gz CPAN: Digest::MD5 loaded ok Fetching with LWP: ftp://mirrors.kernel.org/pub/CPAN/authors/id/M/MA/MARKOV/CHECKSUMS Checksum for /root/.cpan/sources/authors/id/M/MA/MARKOV/MailTools-1.61.tar.gz ok Scanning cache /root/.cpan/build for sizes MailTools-1.61/ MailTools-1.61/t/ ... MailTools-1.61/ChangeLog MailTools-1.61/MANIFEST CPAN.pm: Going to build M/MA/MARKOV/MailTools-1.61.tar.gz Checking for Net::SMTP...ok Checking for Net::Domain...ok Checking for IO::Handle...ok Checking if your kit is complete... Looks good Writing Makefile for Mail cp Mail/Mailer/rfc822.pm blib/lib/Mail/Mailer/rfc822.pm cp Mail/Cap.pm blib/lib/Mail/Cap.pm cp Mail/Header.pm blib/lib/Mail/Header.pm ... /usr/bin/make -- OK Running make test ... All tests successful. Files=7, Tests=93, 3 wallclock secs ( 1.56 cusr + 1.11 csys = 2.67 CPU) /usr/bin/make test -- OK Running make install Installing /usr/lib/perl5/site_perl/5.8.3/Mail/Mailer.pm Installing /usr/lib/perl5/site_perl/5.8.3/Mail/Send.pm ... Installing /usr/share/man/man3/Mail::Field::AddrList.3pm Installing /usr/share/man/man3/Mail::Field.3pm Writing /usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi/auto/Mail/.packlist Appending installation info to /usr/lib/perl5/5.8.3/i386-linux-thread-multi/perllocal.pod /usr/bin/make install -- OK cpan> exit Lockfile removed.
The entire installation process is simple and straightforward. And you can get more information on all of the commands that the CPAN shell supports by issuing the help command. If, however, you don t want to use the shell, you can download the source directly from CPAN and build it yourself. This will provide you with a bit more control, but you need to make sure to install any prerequisite modules that are needed by the extension that you are building before hand. If you do use the shell, it is intelligent enough to install these modules for you automatically, provided that the module authors followed certain conventions for specifying prerequisites.
You have now looked at what Perl is, how it compares to other programming languages, what its advantages and disadvantages are, and how to install it. The next step is to actually learn the language.