Re: How to export constants to a module?
- From: Mike Heins <mikeh@xxxxxxxxxxxx>
- Date: Tue, 19 Apr 2005 05:15:23 -0000
On 2005-04-19, Harris More <nogot@xxxxxxxxxxx> wrote:
> How do I export a constant to a pm module? Or maybe the question is, How
> do I make a constant in the caller routine visible to modules?
>
> This is one of those things that is either so simple that "everybody"
> (except me) knows how to do it, or so simple that I am not seeing the
> forest for the trees. It is probably in perldocs but so far I have come up
> blank. Can't get around the "Bareword not allowed while strict subs..."
>
> I hate to have to assign the constant to a variable to move it across the
> interface, especially since I have a LOT of constants. So far I have
> learned a ton of good stuff trying to fix it, but unfortunately nothing
> about making constants visible to a module.
I don't often use constants, but it seems it is as simple as:
## Begin FooConstant.pm
package FooConstant;
require Exporter;
@ISA = qw/ Exporter /;
@EXPORT = qw/FOO/;
use constant { FOO => 'bar' };
1;
## End FooConstant.pm
Then call the module with:
## Begin FooNeeder.pl
use FooConstant;
my $out = 'voila: ' . FOO;
print $out;
--
Mike Heins
Perusion -- Expert Interchange Consulting http://www.perusion.com/
Be patient. God isn't finished with me yet. -- unknown
.
- References:
- How to export constants to a module?
- From: Harris More
- How to export constants to a module?
- Prev by Date: Re: How to export constants to a module?
- Next by Date: Re: my $hh = %hash
- Previous by thread: Re: How to export constants to a module?
- Next by thread: Re: How to export constants to a module?
- Index(es):
Relevant Pages
|