[kw-pm] potentially dumb perl question regarding packages

John Macdonald john at perlwolf.com
Thu Oct 27 19:50:46 PDT 2005


On Thu, Oct 27, 2005 at 02:26:01PM -0400, Robert P. J. Day wrote:
> On Thu, 27 Oct 2005, John Macdonald wrote:
> 
> > The .pl extension stands for Perl Library and it was used back in
> > perl 4 days - before packages and modules were invented. They still
> > work, of course.  Specifying a package name in top level code makes
> > subsequent global names default to that package instead of the
> > default "main" package.  So, any subroutines defined after the
> > package statement, or any global variables referenced will be in
> > that package.  If there are any uses of "fred::foo" (or the older
> > variant "fred'foo") in the other files, they refer to the variable
> > or subroutine named "foo" defined in the package "fred".  If there
> > are no such references, then the package declaration was probably
> > being used to make the variables/subroutines used in that code be
> > separate from variables/subroutines of teh same name in other files.
> > (And the programmer learned perl in the days before the "my"
> > declaration was added to the language and hadn't gotten around to
> > using that new-fangled invention yet. :-)
> 
> in short, in my context, it doesn't *hurt* but it has no value.

If any of the code elsewhere uses global variables with common
names, then removing the package declaration might lead to
errors as two separate pieces of code use the same variable
for two different purposes, and that could hurt.

-- 


More information about the kw-pm mailing list