I know that exporting variables/functions is bad style possibly leading to collisions, but I expected it to work.

I have a scenario where I am placing a package (w.pm) in a subdirectory and when doing so the export/import seems to fail.

when I load the package with:

 use w;  # the package lives in one of the directories in @INC

everything works as expected -> exported variables and functions are available in (and pollute) main's namespace.

When I load the package with:  use A::w; # ./A is not in @INC the package loads fine (the BEGIN{} startup message is issued) and I can use variables/functions when specifying the package name with w::, but not without it.

Am I misreading how to use Exporter, @EXPORT, or is my understanding of how to create packages in a folder hierarchy wrong?

Any insight is appreciated.

-Steffen (using v5.8.8)

main:

#!/tool/pandora64/bin/perl -w -I ./ use strict; use warnings; use v; # variables/funcs work without v::, the package code is a +lmost the same) #use w; # This makes variables/funcs work without w:: use A::w; # this requires w:: to identify the package sub_in_v(); w::sub_in_w(); $var_in_v = "v-variable"; $w::var_in_w = "w-variable"; # works only because of the w:: when use- +ing A::w printf("%s\n", $var_in_v); printf("%s\n", $w::var_in_w); # works only because of the w:: when us +e-ing A::w print(join("\n", @INC)); 1;
package w:
package w; # in ./A use Data::Dumper; use Exporter; our $var_in_w; our @EXPORT= ('$var_in_w', 'sub_in_w'); our @ISA = qw(Exporter); sub sub_in_w{ print("this is from a sub in package SRAM::w!\n"); } BEGIN{ print('this is w\'s BEGIN, @ISA = ', Dumper @ISA, "\n"); 1; } END{ print("w ending now.\n"); } 1;

In reply to variable import from package fails even though package apparently loads by spoonervt

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.