Skip to main content
Book cover

Pro Perl pp 261–276Cite as

Using Modules

  • Chapter
  • 1147 Accesses

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

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Rights and permissions

Reprints 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

Publish with us

Policies and ethics