Chapter 7. Packages, Modules, and Objects

Over the years, Perl has evolved from a utilitarian scripting tool into a sophisticated object-oriented programming language. Many people continue to use Perl just for simple scripts, and Perl will continue to make simple tasks easy. However, Perl can also make difficult tasks possible, by writing reusable code and using object-oriented programming techniques.

This chapter explains what Perl modules are and how to use them in your programs. Modules are written to accomplish tasks that either aren’t implemented by Perl’s built-in functions, or that could be done better. We say modules are “reusable” because anyone who needs to accomplish the same task can use that module instead of writing the code from scratch. As you write more and more Perl code, you’ll undoubtedly find yourself using many of the modules other Perl programmers have provided. You may also find yourself writing modules and making them available for others to use.

The remainder of this book describes a significant portion of the functionality that’s present in publicly available Perl modules. You’ll find that a number of standard or core modules are distributed with Perl; many of these modules are discussed in Chapter 8. Scores of other modules are available on CPAN, and virtually any task you’d like to accomplish in Perl is implemented in a module found there. For unbundled modules, you’ll need to install the module on your system, and then integrate it into your program ...

Get Perl in a Nutshell 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.