Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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. :)


Comment on Re: Sharing the scalar love?
Select or Download Code
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

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-12-18 00:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (41 votes), past polls