Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Sharing the scalar love?

by TVSET (Chaplain)
on Dec 22, 2003 at 21:05 UTC ( #316481=note: print w/replies, xml ) Need Help??

in reply to Sharing the scalar love?

Here is how I usually do it:

1. Create a separate module with all the shared staff:

package Common; use constant GLOB_DEBUG_MODE = 1; use constant GLOB_SITE_NAME = 'My site'; 1;
2. use Common; from anywhere that I need. For example:
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
    I'm assuming that the file in "1. Create a separate module with all the shared staff:" is called Config in part 2 which strikes me as odd.... perhaps a typo in "(Config::GLOB_DEBUG_MODE)"? I'm still sorta trying to figure this out. But my confusion says that perhaps "(Common::GLOB_DEBUG_MODE)" is what you meant?
    If that is the case you have helped me out greatly!
    Update: After looking over the rest of the replies I think that probably is the case, but massive brownie points for responding 99% perfectly in under 2 minutes of me posting

    all code is tested, and doesn't work so there :p (varient on common PM sig for my own ammusment)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://316481]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2020-08-13 15:19 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (74 votes). Check out past polls.