Modules and CPAN

 < Day Day Up > 

A great strength of the Perl community (and the Linux community) is the fact that it is an open-source community. This community support is expressed for Perl via CPAN, which is a network of mirrors of a repository of Perl code.

Most of CPAN is made up of modules, whichare reusable chunks of code that do useful things, similar to software libraries containing functions for C programmers. These modules help speed development when building Perl programs and free Perl hackers from repeatedly reinventing the wheel when building a bicycle.

There are thousands of Perl modules that do everything from sending email to maintaining your Cisco router access lists to telling you whether a name is masculine or feminine to printing the time in some fancy format. If you can think of doing something with a Perl script, chances are pretty good that a module exists to help you. If there's no module that helps, you're encouraged to write one and share it with the rest of the community.

Perl comes with a set of standard modules installed. Those modules should contain much of the functionality that you will initially need with Perl. If you need to use a module not installed with Fedora, use the CPAN module (which is one of the standard modules) to download and install other modules onto your system. At http://www.perl.com/CPAN/, you will find the CPAN Multiplex Dispatcher, which will attempt to direct you to the CPAN site closest to you.

Typing the following command will put you into an interactive shell that gives you access to CPAN. You can type help at the prompt to get more information on how to use the CPAN program.

 $ perl -MCPAN -e shell 

After you have installed a module from CPAN (or written one of your own), you can load that module into memory where you can use it with the use function:

 use Time::CTime; 

use looks in the directories listed in the variable @INC for the module. In this example, use looks for a directory called Time, which contains a file called CTime.pm, which in turn is assumed to contain a package called Time::CTime. The distribution of each module should contain documentation on using that module.

For a list of all the standard Perl modules (those that come with Perl when you install it), see perlmodlib in the Perl documentation. You can read this document by typing perldoc perlmodlib at the command prompt.

     < Day Day Up > 


    Red Hat Fedora 4 Unleashed
    Red Hat Fedora 4 Unleashed
    ISBN: 0672327929
    EAN: 2147483647
    Year: 2006
    Pages: 361

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net