Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
perlfunc:useby gods (Initiate) |
on Aug 24, 1999 at 22:43 UTC ( [id://348]=perlfunc: print w/replies, xml ) | Need Help?? |
useSee the current Perl documentation for use. Here is our local, out-dated (pre-5.6) version: use - load in a module at compile time
use Module LIST use Module use Module VERSION LIST 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. If the first argument to use is a number, it is treated as a version number instead of a module name. If the version of the Perl interpreter is less than VERSION, then an error message is printed and Perl exits immediately. 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 If you don't want your namespace altered, explicitly supply an empty list:
use Module (); That is exactly equivalent to
BEGIN { require Module }
If the
VERSION argument is present between Module and
LIST, then the
use will 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
Because this is a wide-open interface, pragmas (compiler directives) are also implemented this way. Currently implemented pragmas are:
use integer; use diagnostics; use sigtrap qw(SEGV BUS); use strict qw(subs vars refs); use subs qw(afunc blurfl);
Some of these these pseudo-modules import semantics into the current block
scope (like
There's a corresponding ``no'' command that unimports meanings imported by use, i.e., it calls
no integer; no strict 'refs';
If no See the perlmod manpage for a list of standard modules and pragmas. |
|