Whoops! Just when I thought I was getting past the newbie stage, something like this comes along. As they say in the film This Is Spinal Tap, "it is a fine line between clever and stupid."

Yes, the Require Exporter statement is superfluous. The code works or breaks the same with or without it.

Yes, changing the variable name from $a to $aa in the Exporter example breaks the program. (Who would have thought it?)

And yes, using my() in the package MyPack indeed renders the lexical variable invisible outside of the package. What does work, surprisingly to me, is the following:

#tempo2.pl use strict; use MyPack; my $myString = $MyPack::aa; print $myString;
and
#MyPack.pm package MyPack; use strict; $MyPack::aa = "Read from Mypack"

Which only goes to show that a global package variable is, well, global—it is visible by default when called using the name of its package.

The Exporter module, then, must be for some other purpose entirely besides making variables global.

A few simple concepts: scope, packages. How does it get to be so complicated to us newbies?

Update: After R(ing)TFM, I realize that Exporter can export the namespace of package variables outside of that package. However, I was not calling it properly; I was not giving it anything to export.


In reply to Re: Re(7): Usage of our by sierrathedog04
in thread Usage of our by Anonymous Monk

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.