in reply to constants in multiple libraries
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: constants in multiple libraries
by shemp (Deacon) on Sep 17, 2004 at 20:58 UTC | |
by JediWizard (Deacon) on Sep 20, 2004 at 14:23 UTC |