in reply to Using Global Variables in Perl
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:
Then other modules can selectively import them into their own namespace via:package moduleA; @ISA = qw(Exporter); @EXPORT_OK = qw($readMode $writeMode $appendMode openFile); $readMode = ''; $writeMode = '>'; ... 1;
use moduleA qw($appendMode openFile); ... # calls moduleA::openFile() with parameter $moduleA::appendMode: openFile(..., $appendMode); # note: no namespace qualifier needed
|
|---|