develooper Front page | perl.beginners | Postings from December 2002

moving a large hash to a library and using data from args to populate it

From:
Ian Zapczynski
Date:
December 3, 2002 14:20
Subject:
moving a large hash to a library and using data from args to populate it
Message ID:
3DED2E36.1020804@quarterleaf.com
Hello all,

I am writing a script which requires that a very large multi-level hash 
be populated at the start.   I am trying to write something somewhat 
efficient so I can use a somewhat small loop to do a whole lot of work. 
 Unfortunately, the size of the hash makes my script look rather ugly, 
so I thought it would make sense to move it over to a library/module so 
that it can be referenced by those who will read my code only when 
necessary.  Hopefully this is a logical thing to do; if not, I'm more 
than happy to listen to opinions.

My question comes from the following dilemma:  My script is accepting 
arguments which it uses to populate a string.  That string then needs to 
be used to partially populate the hash.  For example,

# my Perl script has this
my ($PO) = @ARGV;


# my module has this
%dbstuff = ( 0    =>[ { tag       => "XML tag",
                          condition     => "SELECT $rpo FROM 
purchase_orders" } ],
);

This is a very dumbed-down version of what I'm doing, which is to 
populate a hash with database sql queries.  The results of which, when 
executed in a loop, will be written out to an XML file (hence the need 
for the XML tag element in my hash).   As an aside, the key "0" in the 
example above is used so I can reference the original order in which 
they are populated.  I read about Tie::Hash, but it did not seem to be 
exactly what I want in this case.

So my question is, can I move my hash to a library/module AND still use 
the arguments to my perl script to populate it?  I thought of moving my 
hash to a subroutine to do so, but then I lose my nifty way of 
referencing the data by means like $MyModule::dbstuff{$key}[0]{tag}, no?  

Any ideas or criticisms are certainly welcome.

-Ian




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About