[Previous] [Contents] [Next]


The Perl5 Module: Form and Function

The typical Perl module is a file that lives in the Perl library directories, @INC, and has Perl code that can be imported into your Perl program, through the use or require statements. If you've used Perl4, then you're probably familiar with require. The use() statement implies a BEGIN{} block, and thus the importation of the module's symbols occurs immediately. In general, the use() statement gives preferred functionality over the require statement, but they're each used widely. See PERLMOD for more details.

After the code from the module is loaded into your Perl program, it can be used as if it were part of your program. Thus, a module typically provides useful subroutines (methods) that you can call, possibly passing in Perl variables and receiving back a simple result or modified or new variables. Such behavior is typical of both Perl modules and libraries. A Simple Extension Module A typical Perl5 module that provides an extension to an external API looks something like
Listing 2.1.

[Previous] [Contents] [Next]