Name
package
Synopsis
package namespace
Description
Declares that the rest of the
innermost enclosing block, subroutine, eval
or file belongs to the indicated namespace. (The scope of a package
declaration
is thus the same as the scope of a
local
or my
declaration.) All subsequent references to unqualified
global identifiers will be resolved by looking them up in the declared packages
symbol table. A package
declaration affects
only global variables—including those you’ve used local
on—but not
lexical variables created with my
.
Typically you would put a package
declaration as the first thing in a file that
is to be included by the require
or use
operator, but you can put one anywhere that a
statement would be legal. When defining a class or a module file, it is
customary to name the package the same name as the file, to avoid confusion.
(It’s also customary to name such packages beginning with a capital letter,
because lowercase modules are, by convention, interpreted as pragmas.)
Get Perl in a Nutshell 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.