Skip to main content


Importing Modules


Perl modules generally export functions/variables (most of them) or affect the lexical environment (pragmas, like strict/warnings) or are weird. We'll ignore the third kind. Symbol exporters usually affect the package they're used from, but there are some exceptions (e.g. builtin exports to the lexical environment). We'll ignore lexical exporters as well.

Here are some of the ways you can load modules in Perl:

  • use Some::Module; gives you the "default" behavior/exports, whatever that is for a given module.
  • use Some::Module "list", "of", "args"; passes the arguments to the module to do whatever. For symbol exporters this is normally the list of symbols you'd like to import.
  • use Some::Module (); (an explicit empty import list) loads a module without importing anything.
  • require Some::Module; also loads a module without importing anything, but at runtime, not compile time.
  • { use Some::Module; } imports package symbols, but inhibits pragma effects. (For example, { use Moose; } gives you helpers like has or extends, but does not turn on strict/warnings.)
  • package My::Package::_Dummy; use Some::Module; package My::Package; provides the opposite effect: It enables lexical effects, but diverts exported symbols to a different package.

#perl #modules

Unknown parent

mastodon - Link to source
Füsilier Breitlinger
@choroba I would! 😁 But you're right, maybe I should've said "modules with a non-trivial import".