in reply to sharing symbols
In case you'd (only) use the pragma constant to declare your constants, you could use its hash %constant::declared to get the list of names to export. Something like this
Your module with the constants:
package MyConsts; use constant { CONST1 => 123, CONST2 => 1.11, CONST3 => "foo", CONST4 => ["foo", "bar"], }; use constant CONST5 => qw(foo bar); use Exporter 'import'; our @EXPORT = map /([^:]+)$/, keys %constant::declared; 1;
How to make use of it:
#!/usr/bin/perl use strict; use warnings; use MyConsts; print CONST1, "\n"; # or some weirder cases (just to illustrate, # I understand that you only need integers) print "@{CONST4()}\n"; # -> foo bar print "@{[CONST5]}\n"; # -> foo bar print +(CONST5)[1], "\n"; # -> bar
|
|---|