> -----Original Message-----
> From: Jerry Preston [mailto:[EMAIL PROTECTED]]
> Sent: Monday, June 10, 2002 12:32 PM
> To: Beginners Perl
> Subject: hashing in a package
> 
> 
> Hi!
> 
> I have a number of hash's that use over and over.  Currently 
> I can access
> via a "require file_name".  I would to put these in a package 
> and access
> them, but I do not know how.   Any ideas?
> 
>   %T_HASH = (
>                         a => [ "d", "e", "f", ],
> 
>                         b => [ "g", "h", "i", ],
> 
>                         c => [ "j", ],
>                     );
> 

Create a module in a separate file like this:

File MyHash.pm:

   package MyHash;

   use strict;
   require Exporter;

   our @ISA = qw(Exporter);
   our @EXPORT = qw();
   our @EXPORT_OK = qw(%T_HASH);

   %T_HASH = (
       a => [ "d", "e", "f", ],
       b => [ "g", "h", "i", ],
       c => [ "j", ],
   );

   1;        # module must end with a "true" value

Now in your main program, just:

   use MyHash;
   print @{$MyHash::T_HASH{a});

To import %T_HASH into current package:

   use MyHash qw(%T_HASH);
   print @{$T_HASH{a}};

Read:

   perldoc Exporter
   perldoc perlmodlib

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to