require() doesn't import. You need to use "use" or call import() yourself. See Exporter and use. Also, q() does not strip spaces. you generally want to use qw() anyway, since that allows you to easily specify a list of space-separated "words".

Additionally, you can only have one package-global variable of the same type and the same name in the same package, so the second import will override the first.

use dir_one::my_package qw(%my_hash); BEGIN { # force this to run before the "use" below print "%s\n", Dumper(\%my_hash); } use dir_two::my_package qw(%my_hash); print "%s\n", Dumper(\%my_hash);

update: also, print() doesn't do what you seem to think it does. See print and printf/sprintf. in this case,

print Dumper(\%my_hash);
will suffice.

update 2: almut reminded me that since you specified "%my_hash" in @EXPORT (and not @EXPORT_OK) it will get exported automatically, so you don't need to specify it again when importing. You still need to use "use" or call import yourself, though. That would make the final code something like this:

use dir_one::my_package; BEGIN { # force this to run before the "use" below print Dumper(\%my_hash); } use dir_two::my_package; print Dumper(\%my_hash);

In reply to Re: access to hashes with same name, from different packages with same name by Joost
in thread access to hashes with same name, from different packages with same name by utku

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.