Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Using Global Variables in Perl

by pc88mxer (Vicar)
on Apr 22, 2008 at 17:12 UTC ( [id://682223]=note: print w/replies, xml ) Need Help??


in reply to Using Global Variables in Perl

++ on the Best Practices suggestion.

I think this situation is a good candidate for using exported symbols. Have package moduleA export $readMode, etc. which other modules can import. The implementation would go something like:

package moduleA; @ISA = qw(Exporter); @EXPORT_OK = qw($readMode $writeMode $appendMode openFile); $readMode = ''; $writeMode = '>'; ... 1;
Then other modules can selectively import them into their own namespace via:
use moduleA qw($appendMode openFile); ... # calls moduleA::openFile() with parameter $moduleA::appendMode: openFile(..., $appendMode); # note: no namespace qualifier needed

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-25 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found