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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.