Using
Exporter isn't really a huge hassle, since you can virtually auto-import if you declare them using something other than a whole whack of variables.
Something to consider is using a global hash instead of a thousand global variables. Then you can have virtually unlimited access to "globals" without having to explicitly declare them.
Further to that, if you really have thousands of "constants", these should probably come from a config file anyway, unless, of course, these are strictly related to the internals of the program.
The more ambitious approach is to write your own
import function and stuff references to your globals into the calling module. Consider:
package Foo;
our $a = "a";
our $b = "b";
sub import
{
my ($self) = @_;
my ($caller_package) = caller;
foreach (keys %{"${self}::"})
{
*{"${caller_package}::$_"} = *$_;
}
}
Now this will export
everything that is exportable,
that being those things declared with
our instead of
my.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.