It may just be my own personal prejudice, but I perfer not to ever require a .pl file. Whenever I move code out of the main script, I put it in a module (.pm) and use it.
Another standard practice I have found helpfull is to always start a module with a package declaration, and simply export anything that may be needed in the client code. I have actually run into problems with modules that do not have a package declaration. See the blow example:
#File Foo.pm sub make_foo { # do stuff } #File Bar.pm package Bar; use Foo; sub make_bar { &make_foo(); # It is defined here. # do stuff } #File myScript.pl #!/usr/local/bin/perl -w use strict; use Bar; use Foo; &make_foo(); # Undefined subroutine!
Becuase Bar.pm was included before Foo.pm, Foo.pm was compiled into the Bar:: namespace and now &main::make_foo(); is an undefined subroutine. Not good.
In reply to Re: constants in multiple libraries
by JediWizard
in thread constants in multiple libraries
by shemp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |