Packages

B.3 Packages

Packages[B] allow you to compartmentalize the namespaces. Imagine that you have ten programmers all working on one big project. If you use the global names $fred, @barney, %betty, and &wilma in your part of the project, what happens when I accidentally use one of those same names in my part? Packages let us keep these separate; I can access your $fred, and you can access mine, but not by accident. Packages are needed to make Perl scalable, so that we can manage large programs.

[B] The name "package" is perhaps an unfortunate choice, in that it makes many people think of a packaged-up chunk of code (in Perl, that's a module or a library). All that a package does is define a namespace (a collection of global symbol names, like $fred or &wilma). A namespace is not a chunk of code.

 



Learning Perl
Learning Perl, 5th Edition
ISBN: 0596520107
EAN: 2147483647
Year: 2001
Pages: 205

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net