Packages and Modules

import module [ list ]

Usually imports subroutines and variables from module into the current package. import is not a built-in, but an ordinary class method that may be inherited from UNIVERSAL.

no module [ list ]

At compile time, requires the module and calls its unimport method on list. See use on the next page.

package namespace [ version ] [ block ]

Designates the block as a package with a namespace. Without block, applies to the remainder of the current block or file. Sets package variable $VERSION to version, if specified.

require version

Requires Perl to be at least this version. version can be numeric like 5.005 or 5.008001, or a v-string like v5.8.1.

require expr†

If expr is numeric, behaves like require version. Otherwise expr must be the name of a file that is included from the Perl library. Does not include more than once, and yields a fatal error if the file does not evaluate to true. If expr is a bare word, assumes extension .pm for the name of the file.

unimport module [ list ]

Usually cancels the effects of a previous import or use. Like import, unimport is not a built-in, but an ordinary class method.

use version
use pragma

See the section Pragmatic Modules below.

By convention, pragma names start with a lowercase letter.

use module [ version ] [ list ]

At compile time, requires the module, optionally verifies the version, and calls its import method on list.

If list is (), doesn’t call import.

Normally used to import a list of variables and subroutines from ...

Get Perl Pocket Reference, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.