Chapter 11. Modules
The module is the fundamental unit of code reuse in Perl. Under the hood, it’s just a package defined in a file of the same name (with .pm on the end). In this chapter, we’ll explore how you can use other people’s modules and create your own.
Perl comes bundled with hundreds of useful modules, which you can find in the lib directory of your Perl distribution, which are decided at the time you (or someone) built perl. You can see where these directories are with the –V switch:
% perl –V
Summary of my perl5 (revision 5 version 14 subversion 1) configuration:
...
Built under darwin
Compiled at Jul 5 2011 21:43:59
@INC:
/usr/local/perl/lib/site_perl/5.14.2/darwin–2level
/usr/local/perl/lib/site_perl/5.14.2
/usr/local/perl/lib/5.14.2/darwin–2level
/usr/local/perl/lib/5.14.2
.You can see all of the modules that come with perl with corelist, which also comes with perl:
% corelist –v 5.014All standard modules also have extensive online documentation, which (horrors) will most likely be more up to date than this book. Try the perldoc command to read the documentation:
% perldoc Digest::MD5The Comprehensive Perl Archive Network (CPAN) contains a worldwide repository of modules contributed by the Perl community, and is discussed in Chapter 19. See also http://www.cpan.org.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access