Книга: Fedora™ Unleashed, 2008 edition

Modules and CPAN

Modules and CPAN

A great strength of the Perl community (and the Linux community) is 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, which are reuseable 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.

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 attempts to direct you to the CPAN site closest to you.

Typing the following command puts 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.

Related Fedora and Linux Commands

You will use these commands and tools when using Perl with Linux:

a2p — A filter used to translate awk scripts into Perl

find2perl — A utility used to create Perl code from command lines, using the find command

pcregrep — A utility used to search data, using Perl-compatible regular expressions

perlcc — A compiler for Perl programs

perldoc — A Perl utility used to read Perl documentation

s2p — A filter used to translate sed scripts into Perl

vi — The vi (actually vim) text editor

Оглавление книги


Генерация: 1.246. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз