Declares the compilation unit as being in the given namespace. The scope of the package declaration is from the declaration itself through the end of the enclosing block, file, or eval (the same as themy operator). All further unqualified dynamic identifiers will be in this namespace. A package statement affects only dynamic variables--including those you've usedlocal on--butnot lexical variables, which are created withmy. Typically it would be the first declaration in a file to be included by therequire oruse operator. You can switch into a package in more than one place; it merely influences which symbol table is used by the compiler for the rest of that block. You can refer to variables and filehandles in other packages by prefixing the identifier with the package name and a double colon:$Package::Variable. If the package name is null, themain package as assumed. That is,$::sail is equivalent to$main::sail (as well as to$main'sail, still seen in older code).
If NAMESPACE is omitted, then there is no current package, and all identifiers must be fully qualified or lexicals. This is stricter thanuse strict, since it also extends to function names.
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.