You can export variables using exactly the same Exporter mechanism as you can with subroutines. E.g:
which works fine. Note that the exported variables must be package and not lexical variables: you need to declare them in the module with use vars or our (or use the fully package qualified name) and not declare them with my.(PackVar.pm): package PackVar; + use base Exporter; + use vars qw(@EXPORT $Test); + @EXPORT = qw($Test); + $Test = 1; + 1; (test.pl): use strict; + use PackVar; + print $Test,"\n";
However you really, really, really do want to think carefully about exporting variables like this even more than you do with subroutines as this constitutes a more serious pollution of the callers namespace with a higher risk of collision, unless you have absolutely no way around this you should use fully package qualified names (e.g. $PackVar::Test) in the caller and document this usage.
/J\
In reply to Re: Access to (exported?) variabes of a module
by gellyfish
in thread Access to (exported?) variabes of a module
by jeanluca
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |