in reply to Global variable declarations with packages

Your description is too vague to do more than guess at the problem, but one possible source of confusion might be that import doesn't export the functions you're expecting it to because the initialization code for @EXPORT et al has not yet run.

Try surrounding the code with BEGIN { } to make sure any necessary initialization happens at compile time. This is done implicitly when you use a module — if you include code directly in your script, you have to provide for this yourself.

I am not sure I understand which variables you need to declare. Are they in package main, but referenced from other packages?

Makeshifts last the longest.

  • Comment on Re: Global variable declarations with packages

Replies are listed 'Best First'.
Re^2: Global variable declarations with packages
by spoulson (Beadle) on Aug 10, 2004 at 12:52 UTC
    Yes, the packages did have use Exporter, @ISA, and @EXPORT properly defined. Aha... I think I found the problem. The poorly written code seems to have a mismatched brace, causing the package main; to operate within a code block. I tried to duplicate my situation with some code, but apparently it didn't complain about varaiable declaration. i.e.:
    package MYMODULE::THING; use Exporter; @ISA = qw(Exporter); @EXPORT = qw(Func1 Func2); sub Func1 {} sub Func2 {} package main; import MYMODULE::THING; $somevar = 1; @somearray = (1, 2, 3); ...
    ...works fine. It appears I need to dig further into this junk. Thanks.