[kw-pm] potentially dumb perl question regarding packages

John Macdonald john at perlwolf.com
Thu Oct 27 12:01:14 PDT 2005


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. :-)

On Thu, Oct 27, 2005 at 01:51:01PM -0400, Robert P. J. Day wrote:
> 
>   some perl code i've inherited has a number of ".pl" files with the
> following structure -- consider a sample file fred.pl:
> 
> =============================
> 
> #!/usr/bin/perl
> ...
> 
> package fred;
> 
> ... executable code ...
> 
> 1;
> 
> ==============================
> 
>   i understand the concept of defining a package name in a .pm file,
> but this is just a regular executable file and it doesn't appear to
> need to be part of any package.
> 
>   what is the rationale for defining a package for a top-level
> executable file?
> 
> rday
> 
> p.s.  this file *does* "use" a number of module files, but they have
> no relation to the above package name in any way.
> _______________________________________________
> kw-pm mailing list
> kw-pm at pm.org
> http://mail.pm.org/mailman/listinfo/kw-pm

-- 


More information about the kw-pm mailing list