in reply to Inheritance

Whoa! Back up a minute!

To export something from a module you need to use:

use Exporter; # require works; @ISA = 'Exporter'; @EXPORT_OK = qw(functions $variables @arrays); # I put this after the above, some put this above and then use "our". use strict;
and then your caller has to use Foo qw(functions $variables @arrays);

What you wrote, by contrast, has several syntax errors, forgets that Perl is case-sensitive, and has some more subtle mistakes (eg the , inside of qw()). One of the more subtle mistakes is choosing to use @EXPORT instead of @EXPORT_OK, which works, but which will make debugging much harder. (Where did this come from?)

As for the question that you're asking, the simple way to do it is to use fully qualified package names. Like this:

# In the main script... use strict; use vars qw($foo); # ... time passes ... $foo = "whatever"; # In the module... print $main::foo;
If you're tired of typing those variables time after time, you could always create a module whose job is to hold all of the variables that you want to share. Then you can just use that module from everywhere and the variables will be in your namespace.

PS: Note that I've pushed you towards using strict.pm. There are good reasons for that...

Replies are listed 'Best First'.
Re^2: Inheritance
by salva (Canon) on Jun 04, 2005 at 02:17 UTC
    @EXPORT instead of @EXPORT_OK, which works, but which will make debugging much harder

    This is not related to debugging.

    The difference is that subs and vars included in @EXPORT will always be exported to the modules use'ing the module, while on the other hand, things included on @EXPORT_OK will only be exported when explicitely requested on the use statement.

    The problem with @EXPORT is namespace pollution that leads to name collisions when exported functions are added in new versions of some module.

      The difference is that subs and vars included in @EXPORT will always be exported to the modules use'ing the module...

      Not to be overly retentive here, but that's not quite right. Or at least not sufficiently clear. In the empty list case -

      use Some::Module ();

      - no symbols are exported, even the ones in @EXPORT. In fact, @EXPORT are only imported in the default (unspecified) case. If you specify your imports explicitly, then you only get what you ask for.

      There is also a debugging problem. Two of them in fact.

      The first debugging problem is figuring out what happened after name collisions. (Creating bugs leads to debugging...) The second, and to me more important, one is the added trouble in finding the functions and variables that you see being called and accessed.