in reply to Sharing the scalar love?
Here is how I usually do it:
1. Create a separate module with all the shared staff:
2. use Common; from anywhere that I need. For example:package Common; use constant GLOB_DEBUG_MODE = 1; use constant GLOB_SITE_NAME = 'My site'; 1;
package Main; use Common; sub print_message { my $msg = shift; # Use default site name if no message specified. unless ($msg) { $msg = Common::GLOB_SITE_NAME; } # Prepend with "DEBUG: " if in debug mode. $msg = "DEBUG: $msg" if (Common::GLOB_DEBUG_MODE); print $msg; } 1;
Update: I've answered a bit a wrong question. :) You were asking about global variables, while I described constants. :)
Update: Fixed two misplaced 'Common's. :)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Sharing the scalar love?
by jcpunk (Friar) on Dec 22, 2003 at 21:23 UTC | |
by TVSET (Chaplain) on Dec 23, 2003 at 00:05 UTC |
In Section
Seekers of Perl Wisdom