© William "Bo" Rothwell of One Course Source, Inc. 2020
W. ". RothwellAdvanced Perl Programminghttps://doi.org/10.1007/978-1-4842-5863-7_7

7. Packages and Namespaces

William “Bo” Rothwell1 
(1)
El Cajon, CA, USA
 

Novice Perl programmers typically are told that Perl has no scope by default. While not technically accurate, without packages, variables in Perl appear to be global.

Technically, most variables are not "global". Variables are stored in "namespaces" which are created by packages.

One package exists by default: the main package. To prevent accidentally overwriting variables that exist in other portions of the script, you can create additional namespaces with the package command.

If you create a Perl module that will be called by another Perl program, ...

Get Advanced Perl Programming: From Advanced to Expert 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.