in reply to Inheritance
To export something from a module you need to use:
and then your caller has to use Foo qw(functions $variables @arrays);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;
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:
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.# In the main script... use strict; use vars qw($foo); # ... time passes ... $foo = "whatever"; # In the module... print $main::foo;
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 | |
by fishbot_v2 (Chaplain) on Jun 04, 2005 at 03:17 UTC | |
by tilly (Archbishop) on Jun 04, 2005 at 03:11 UTC |