Chapter 3. Using Modules

Modules are the building blocks for our programs. They provide reusable subroutines, variables, and even object-oriented classes. On our way to building our own modules , we’ll show you some of those you might be interested in. We’ll also look at the basics of using modules that others have already written.

The Standard Distribution

Perl comes with many of the popular modules already. Indeed, most of the 50+ MB of the most recent distribution are from modules. In October 1996, Perl 5.003_07 had 98 modules. Today, at the beginning of 2006, Perl 5.8.8 has 359.[*] Indeed, this is one of the advantages of Perl: it already comes with a lot of stuff that you need to make useful and complex programs without doing a lot of work yourself.

Throughout this book, we’ll try to identify which modules comes with Perl (and in most cases, with which version they started coming with Perl). We’ll call these “core modules " or note that they’re in “the standard distribution .” If you have Perl, you should have these modules. Since we’re using Perl 5.8.7 as we write this, we’ll assume that’s the current version of Perl.

As you develop your code, you may want to consider if you want to use only core modules, so that you can be sure that anyone with Perl will have that module as long as they have at least the same version as you.[] We’ll avoid that debate here, mostly because we love CPAN too much to do without it.

Using Modules

Almost every Perl module comes with documentation, ...

Get Intermediate Perl now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.