in reply to How to access multiple hash variables defined in a module

As zwon writes above, you can always access the hashes with their fully qualified notation %XYZ::Hash1, but you don't need Exporter for that in package XYZ.

However,if you make the hashes available to the caller via @EXPORT_OK, you can import them stating

use XYZ qw(%Hash1 %Hash2);

which makes them accessible as %Hash1 and %Hash2 in the importing namespace.

print "$_ => $Hash1{$_}\n" for keys %Hash1;

Replies are listed 'Best First'.
Re^2: How to access multiple hash variables defined in a module (Exporter)
by Anonymous Monk on Feb 22, 2010 at 09:10 UTC

    I tried both the methods, I am getting able to get only empty hash :(

      Have you tried:

      use strict; use warnings;
      I see require Exporter; line is missed in your example.

      Update: Here's the working code:

      package XYZ; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw(%Hash1); our ( %Hash1, %Hash2 ); sub populateHashRoutine { %Hash1 = ( a => 1, b => 2, ); %Hash2 = ( c => 3, d => 4, ); } 1;
      use strict; use warnings; use Data::Dumper; use XYZ qw(%Hash1); XYZ::populateHashRoutine; warn Dumper \%Hash1, \%XYZ::Hash2; __END__ $VAR1 = { 'a' => 1, 'b' => 2 }; $VAR2 = { 'c' => 3, 'd' => 4 };

      Then it must be empty. Try outputting the hash inside the package.