Declares the BLOCK or the rest of the compilation unit as being in the given namespace. The scope of the package declaration is either the supplied code BLOCK or, in the absence of a BLOCK, from the declaration itself through the end of current scope (the enclosing block, file, oreval). That is, the forms without a BLOCK are operative through the end of the current scope, just like themy,state, andour operators. All unqualified dynamic identifiers in this scope will be in the given namespace, except where overridden by anotherpackage declaration or when they're one of the special identifiers that qualify intomain::, likeSTDOUT,ARGV,ENV, and the punctuation variables.
A package statement affects dynamic variables only, including those you've usedlocal on, butnot lexically-scoped variables, which are created withmy,state, orour. Typically it would be the first declaration in a file included byrequire oruse. You can switch into a package in more than one place, since this only determines which default symbol table the compiler uses for the rest of that block. You can refer to identifiers in other packages than the current one by prefixing the identifier with the package name and a double colon, as in$SomePack::var orThatPack::INPUT_HANDLE. If package name is omitted, themain package as assumed. That is,$::sail is equivalent to$main::sail (as well as to$main'sail, still seen in ancient code, mostly from Perl 4).
If VERSION is provided,package sets the$VERSION variable in the given namespace to aversion object with the VERSION provided. VERSION must be a "strict" style version number as defined by theversion module: a positive decimal number (integer or decimal-fraction) without exponentiation or else a dotted-decimal v-string with a leading 'v' character and at least three components. You should set$VERSION only once per package.
See"Packages" in perlmod for more information about packages, modules, and classes. Seeperlsub for other scoping issues.
Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.
The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.