Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: use variable from main file in a 'require'd file?

by Fletch (Bishop)
on Jun 12, 2006 at 16:41 UTC ( [id://554854]=note: print w/replies, xml ) Need Help??


in reply to use variable from main file in a 'require'd file?

You probably didn't try hard enough. If you declare (in your main program):

our %CONFIG = ( ... );

Then anything else can access it via %main::CONFIG (or %::CONFIG). If it's declared in a different package you'd of course use that package name rather than main. See also Exporter.

Update: Oooh, good catch; I didn't notice the relative ordering of the require and the declaration. You'd need to either swap it or wrap the declaration in a BEGIN block to ensure it happened as soon as possible as well.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-26 05:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found