I was starting to write a constants module (and hating it) when the following funkiness sprang to mind.
This seems nicer to me than the standard way because I don't have to keep track of them in two places (in the constants pragma *and* the export list).
You can also do something like the second one if you really want to go all out.
Update: This only works with 5.8.0. 5.6.1 + earlier don't support creating multiple constants with a single use statement:(
package foo;
use base qw( Exporter );
my %constants;
use constant +{
%constants = (
AAA => 1,
BBB => 2,
CCC => 3,
DDD => 4,
)
};
our @EXPORT = keys %constants;
1;
package foo2;
use base qw( Exporter );
my %all;
my %foo;
my %bar;
use constant +{
%all = (
%foo = (
AAA => 1,
BBB => 2,
),
%bar = (
CCC => 3,
DDD => 4,
),
)
};
our @EXPORT_OK = keys %all;
our %EXPORT_TAGS = (
all => [ keys %all ],
foo => [ keys %foo ],
bar => [ keys %bar ],
);
1;
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.