Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Sharing the scalar love?

by TVSET (Chaplain)
on Dec 22, 2003 at 21:05 UTC ( [id://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

    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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://316481]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2025-05-18 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.