Dr. Mu has asked for the wisdom of the Perl Monks concerning the following question:

This question pertains to ActivePerl 5.8.4 under Win XP. I have a program (Program.pl) that uses some modules I've written (Module, Module::Foo, Module::Bar, etc.). Module.pm uses the exporter to export some global constants (e.g. $X0, $X1, etc.) via @EXPORT, required by the main program as well as the other modules. In Program.pl, I have a "use Module;", and I'm able to access the exported constants without any problem. But in Foo.pm, I also include a "use Module;". Yet there, I get an error: "Global symbol '$X0' requires explicit package name ..." I'm not sure what's going on here and why Foo.pm isn't seeing the exported constants that Program.pl is.

Replies are listed 'Best First'.
Re: Exporter issues
by gaal (Parson) on Oct 28, 2004 at 19:52 UTC
    Apparently, you're hitting a circular dependency. (Does Module use Module::Foo?)

    You can work around the issue by having Module::Foo declare our($X0, $X1) but that's kinda awkward. If these constants are not computed it's probably better to create a Module::Constants that everyone uses, but which doesn't use anyone else in the project.

      Spot on gaal, and ++!! I'm amazed you saw this with so little to go on. Anyway, I created a new module, "Module::Constants", and put the globals there. That broke the dependency cycle, and all is well. Thanks!
Re: Exporter issues
by dragonchild (Archbishop) on Oct 28, 2004 at 19:49 UTC
    Can you create a minimal test case that demonstrates the problem?

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.