I have two packages with same name, but located in different directories, each of which has a hash with same name again:
dir_one/my_package.pm dir_two/my_package.pm
Both file include following:
##! /usr/local/bin/perl package my_package; require(Exporter); @ISA = qw(Exporter); @EXPORT = qw( %my_hash ); %my_hash = ( ... );
The hashes have the same name in each package but their content is different. Now I want to load both packages during runtime, process the hashes in each and so forth. I have done following:
#!/usr/bin/perl -w use Data::Dumper; require dir_one::my_package q( %my_hash ); print "%s\n", Dumper(\%my_hash); require dir_two::my_package q( %my_hash ); print "%s\n", Dumper(\%my_hash);
Perl interpreter tells me that the syntax of "require" is wrong:
syntax error at ./my_script.pl line 7, near "require dir_one::my_packa +ge qw( %my_hash )" Execution of ./my_script.pl aborted due to compilation errors.
Where is my mistake? How can access the hashes in this way during runtime?

In reply to 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.