I'm trying to set up some constants in a module that will be accessible from other code. The final things will be capitalised and I may experiment with other modules to lock them, but for the moment I'm trying the examples from Simple Module Tutorial, but modified for my needs. And I'm getting frustrated. I have two files:
MyModule.pm
package MyModule; use strict; # Case A use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = (); #@EXPORT_OK = qw(func1 func2); @EXPORT_OK = qw(@rray); # %EXPORT_TAGS = ( DEFAULT => [qw(&func1)], # Both => [qw(&func1 &func2)]); # sub func1 { return reverse @_ } # sub func2 { return map{ uc }@_ } # Case B # use Exporter qw(import); # our $VERSION = 1.00; # our @ISA = qw(Exporter); # our @EXPORT_OK = qw(@rray); # All cases my @rray = (1, 2, 3, 4); 1;
MyScript.pl
use strict; # case 1 # use MyModule; # print scalar(@rray); # case 2 # use MyModule; # print scalar(@MyModule::rray); # case 3 use MyModule qw(@rray); print scalar(@rray);
Case 1 returns Global symbol "@rray" requires explicit package name as one would expect. Cases 2 and 3 both print 0. Case A or B makes no difference.
Where have I blundered, please?
TIA & regards,
John Davies
In reply to (Solved) Exporter not behaving as expected by davies
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |