Packages

The scope of a variable refers to that section of the program where a variable can be accessed. In a Perl program without any subroutines, all variables are global to the program. We've seen how a scope can be limited to a subroutine either dynamically, with local, or lexically through the use of my variables. Now we will look at the Perl package capability that allows for a further division of scope.

By default, a program has one package—the main package. You can create other packages by using the package statement. Packages provide a separate namespace so that you can avoid naming collisions. These collisions may happen if you are using libraries from two different sources and each source happens to choose the same name for a function ...

Get Programming PERL in the .NET Environment 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.