Re: How to export constants to a module?



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
.



Relevant Pages

  • Re: Is Fixing a broken Hard Drive possible?
    ... How about a link to some of ton of reviews you have read? ... > again with 90 gig of space free. ... >> You can't fix a hardware type problem with software. ...
    (microsoft.public.windowsxp.hardware)
  • Re: DDX3216 Problem
    ... Patient: "Hey Doc, I've got a headache. ... It's the quality of your diagnosis and the quality of "absolute truth" as they found it actually to be. ... Since you have some idea how easy it is from looking at the pretty pictures on B's Website, you could always order the parts you need from them, and fix it yourself. ...
    (rec.audio.pro)
  • Re: AVG update crashes system?
    ... Well you can't even get on their website now so I hope they fix this real ... > After saying all those good things about AVG... ... So I wonder if they've had a ton ... >>> Dani ...
    (sci.med.transcription)
  • How to export constants to a module?
    ... learned a ton of good stuff trying to fix it, ... Harris ... Prev by Date: ...
    (comp.lang.perl.misc)
  • Re: Relevant Books
    ... You can also take a look at the reviews of AI and machine learning books ... To submit, just post and be patient, or if] ... [ask your news administrator to fix the problems with your system. ...
    (comp.ai)