Perl 5 version 30.0 documentation
- 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
except that Module must be a bareword. The importation can be made conditional by using the if module.
use VERSIONform, VERSION may be either a v-string such as v5.24.1, which will be compared to $^V (aka $PERL_VERSION), or a numeric argument of the form 5.024001, which will be compared to $] . An exception is raised 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. Symmetrically,
no VERSIONallows you to specify that you want a version of Perl older than the specified one.
Specifying VERSION as a numeric argument of the form 5.024001 should generally be avoided as older less readable syntax compared to v5.24.1. Before perl 5.8.0 released in 2002 the more verbose numeric form was the only supported syntax, which is why you might see it in
This is often useful if you need to check the current Perl version before useing library modules that won't work with older versions of Perl. (We try not to do this more than we have to.)
use VERSIONalso lexically enables all features available in the requested version as defined by the feature pragma, disabling any features not in the requested version's feature bundle. See feature. Similarly, if the specified Perl version is greater than or equal to 5.12.0, strictures are enabled lexically as with use strict . Any explicit use of
use VERSION, even if it comes before it. Later use of
use VERSIONwill override all behavior of a previous
use VERSION, possibly removing the
use VERSIONdoes not load the feature.pm or strict.pm files.
BEGINforces the require and import to happen at compile time. The require makes sure the module is loaded into memory if it hasn't been yet. The import is not a builtin; it's just an ordinary static method call into the
Modulepackage to tell the module to import the list of features back into the current package. The module can implement its import method any way it likes, though most modules just choose to derive their import method via inheritance from the
Exporterclass that is defined in the Exporter module. See Exporter. If no import method can be found, then the call is skipped, even if there is an AUTOLOAD method.
If you do not want to call the package's import method (for instance, to stop your namespace from being altered), explicitly supply the empty list:
- use Module ();
That is exactly equivalent to
If the VERSION argument is present between Module and LIST, then the use will call the
VERSIONmethod in class Module with the given version as an argument:
- use Module 12.34;
is equivalent to:
The VERSION argument cannot be an arbitrary expression. It only counts as a VERSION argument if it is a version number literal, starting with either a digit or
vfollowed by a digit. Anything that doesn't look like a version literal will be parsed as the start of the LIST. Nevertheless, many attempts to use an arbitrary expression as a VERSION argument will appear to work, because Exporter's
importmethod handles numeric arguments specially, performing version checks rather than treating them as things to export.
Because this is a wide-open interface, pragmas (compiler directives) are also implemented this way. Some of the currently implemented pragmas are:
Some of these pseudo-modules import semantics into the current block scope (like strict or integer , unlike ordinary modules, which import symbols into the current package (which are effective through the end of the file).
Because use takes effect at compile time, it doesn't respect the ordinary flow control of the code being compiled. In particular, putting a use inside the false branch of a conditional doesn't prevent it from being processed. If a module or pragma only needs to be loaded conditionally, this can be done using the if pragma:
There's a corresponding no declaration that unimports meanings imported by use, i.e., it calls
Module->unimport(LIST)instead of import. It behaves just as import does with VERSION, an omitted or empty LIST, or no unimport method being found.
Care should be taken when using the
no VERSIONform of no. It is only meant to be used to assert that the running Perl is of a earlier version than its argument and not to undo the feature-enabling side effects of