Summary
Over the course of this chapter, we examined what Perl modules are and how they related to files and packages. We started out with an examination of the do, require, and use statements and the differences between them. We then went on to look at the import mechanism provided by Perl and how it can be used to add definitions from modules that we use. We considered the difference between functional and pragmatic modules and found that pragmatic modules turn out to be very much like their functional brethren.
Perl searches for modules using the special array variable @INC and places the details of what was found where in the corresponding special hash variable %INC. We saw how to manipulate @INC in various ways, including directly, and the use lib pragma. We also found out how to ask Perl what modules have been added to the library that did not originally come with Perl.
Finally, we looked at delaying the loading of modules until they are needed with the autouse pragma. This has powerful possibilities for limiting the impact of a Perl application on memory, but not without drawbacks, notably that if a dependent module is not present we will not find out at compile time. Instead, we will only know the first time the application tries to use something from it, which could be a considerable time after it started.
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsPreview
Unable to display preview. Download preview PDF.
Rights and permissions
Copyright information
© 2005 Peter Wainwright
About this chapter
Cite this chapter
(2005). Using Modules. In: Pro Perl. Apress. https://doi.org/10.1007/978-1-4302-0014-7_9
Download citation
DOI: https://doi.org/10.1007/978-1-4302-0014-7_9
Publisher Name: Apress
Print ISBN: 978-1-59059-438-4
Online ISBN: 978-1-4302-0014-7
eBook Packages: Professional and Applied ComputingProfessional and Applied Computing (R0)Apress Access Books