Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: using external file for hashes

by topher (Scribe)
on Jun 05, 2013 at 03:46 UTC ( #1037107=note: print w/ replies, xml ) Need Help??


in reply to using external file for hashes

Is there a reason it needs to be stored in the external file as perl code for hashes? Typically, you would store the data in a data format (CSV, XML, YAML, etc.), and read the data from the file in to build your Perl data structure (hash).

Alternately, if the data is more than a few entries, you might be better off leaving the data on disk, and accessing it on demand. My personal preference for that is SQLite (unless I have specific requirements that suggest something else). For your case, you might want to look at Tie::Hash or something alone that line. This type of module will store the contents of your hash in a database file. To your program, the hash looks and acts pretty much like a standard hash, but the data isn't stored in memory, it's stored on disk.

You could also use a module to implement data structure persistence. Something like Storable (or the numerous similar modules) might be useful for you. It will let you store a data structure (including a hash) on disk, and read it back into your program.

If you are insistent on storing the data as raw Perl code, you should review the documentation on require and do. These can be used to read in perl code from an external source.

Christopher Cashell


Comment on Re: using external file for hashes

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1037107]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2014-09-18 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (103 votes), past polls