Полезная информация

Perl in a Nutshell

Perl in a NutshellSearch this book
Previous: Reference: untieChapter 5
Function Reference
Next: Reference: utime


use Module list
use version
use Module version list

If the first argument is a number, it is treated as a version number. If the version of Perl is less than version, an error message is printed and Perl exits. This provides a way to check the Perl version at compilation time, instead of waiting for runtime.

If version appears between Module and list, then use calls the version method in class Module with version as an argument.

Otherwise, use 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 the following:

BEGIN { require Module; import Module list; }
The BEGIN forces the require and import to happen at compile time. The require makes sure that the module is loaded into memory if it hasn't been yet. The import is not a built-in function - it's just an ordinary static method call into the package named by Module 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 Exporter class that is defined in the Exporter module.

If you don't want your namespace altered, explicitly supply an empty list:

use Module ();
That is exactly equivalent to the following:
BEGIN { require Module; }
Because this is a wide-open interface, pragmas (compiler directives) are also implemented this way. See Chapter 8 for descriptions of the currently implemented pragmas. These pseudomodules typically import semantics into the current block scope, unlike ordinary modules, which import symbols into the current package. (The latter are effective through the end of the file.)

There's a corresponding declaration, no, that "unimports" any meanings originally imported by use, but that have since become less important:

no integer;
no strict 'refs';

Previous: Reference: untiePerl in a NutshellNext: Reference: utime
Reference: untieBook IndexReference: utime