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:
and#tempo2.pl use strict; use MyPack; my $myString = $MyPack::aa; print $myString;
#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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |