EvdB has asked for the wisdom of the Perl Monks concerning the following question:
Method 1: the variable approach:
####### In Config module ########## package My::Config; $My::Config::DB_NAME = 'my_database'; $My::Config::DB_PASS = 'secret'; 1; ####### In another module ######### use My::Config; my $db_name = $My::Config::DB_NAME;
Method 2: The subs approach:
####### In Config module ########## package My::Config; sub DB_NAME { 'my_database' } sub DB_PASS { 'secret' } 1; ####### In another module ######### use My::Config; my $db_name = My::Config::DB_NAME;
Both work very nicely. The variable approach is almost as fast as doing my $db_name = 'my_database'; and three times faster than the subs approach.
I want to go with the sub approach because I can then be sure that the values will not change during the lifetime of the script (under mod_perl this could be a while).
QUESTIONS:
--tidiness is the memory loss of environmental mnemonics
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Variables versus Subroutines for a Configuration Module.
by hardburn (Abbot) on Oct 10, 2003 at 16:25 UTC | |
by EvdB (Deacon) on Oct 10, 2003 at 16:43 UTC | |
by Aristotle (Chancellor) on Oct 10, 2003 at 17:16 UTC |