- use Module VERSION
- use Module LIST
- use Module
- use VERSION
Imports some semantics into the current package from the named module, generally by aliasing certain subroutine or variable names into your package. It is exactly equivalent to
BEGIN { require Module; import Module LIST; }
except that Module must be a bareword.
VERSION may be either a numeric argument such as 5.006, which will be compared to
$], or a literal of the form v5.6.1, which will be compared to$^V(aka $PERL_VERSION. A fatal error is produced if VERSION is greater than the version of the current Perl interpreter; Perl will not attempt to parse the rest of the file. Compare with "require", which can do a similar check at run time.Specifying VERSION as a literal of the form v5.6.1 should generally be avoided, because it leads to misleading error messages under earlier versions of Perl that do not support this syntax. The equivalent numeric version should be used instead.
use v5.6.1; # compile time version check use 5.6.1; # ditto use 5.006_001; # ditto; preferred for backwards compatibility
This is often useful if you need to check the current Perl version before
useing library modules that have changed in incompatible ways from older versions of Perl. (We try not to do this more than we have to.)The
BEGINforces therequireandimportto happen at compile time. Therequiremakes sure the module is loaded into memory if it hasn't been yet. Theimportis not a builtin--it's just an ordinary static method call into theModulepackage to tell the module to import the list of features back into the current package. The module can implement itsimportmethod any way it likes, though most modules just choose to derive theirimportmethod via inheritance from theExporterclass that is defined in theExportermodule. See Exporter. If noimportmethod can be found then the call is skipped.If you do not want to call the package's
importmethod (for instance, to stop your namespace from being altered), explicitly supply the empty list:use Module ();
That is exactly equivalent to
BEGIN { require Module }
If the VERSION argument is present between Module and LIST, then the
usewill call the VERSION method in class Module with the given version as an argument. The default VERSION method, inherited from the UNIVERSAL class, croaks if the given version is larger than the value of the variable$Module::VERSION.Again, there is a distinction between omitting LIST (
importcalled with no arguments) and an explicit empty LIST()(importnot called). Note that there is no comma after VERSION!Because this is a wide-open interface, pragmas (compiler directives) are also implemented this way. Currently implemented pragmas are:
use constant; use diagnostics; use integer; use sigtrap qw(SEGV BUS); use strict qw(subs vars refs); use subs qw(afunc blurfl); use warnings qw(all); use sort qw(stable _quicksort _mergesort);
Some of these pseudo-modules import semantics into the current block scope (like
strictorinteger, unlike ordinary modules, which import symbols into the current package (which are effective through the end of the file).There's a corresponding
nocommand that unimports meanings imported byuse, i.e., it callsunimport Module LISTinstead ofimport.no integer; no strict 'refs'; no warnings;
See perlmodlib for a list of standard modules and pragmas. See perlrun for the
-Mand-mcommand-line options to perl that giveusefunctionality from the command-line.

