Re: save hash to file?
by kennethk (Abbot) on Nov 14, 2010 at 16:10 UTC
|
The simple answer is use the core module Storable. Example from the documentation:
use Storable;
store \%table, 'file';
$hashref = retrieve('file');
| [reply] [d/l] |
Re: save hash to file?
by tokpela (Chaplain) on Nov 14, 2010 at 19:51 UTC
|
Check out DBM::Deep which will allow you to save your hash as a binary file with a very fast lookup.
| [reply] |
|
|
| [reply] |
Re: save hash to file?
by PeterPeiGuo (Hermit) on Nov 14, 2010 at 18:46 UTC
|
A major defect of this idea is that, all data are virtually loaded in memory all the time. Unless the amount of searchable index is limited, I do not consider this as a workable solution.
Use a DB in this case, and leave the momery management to the DB.
| [reply] |
Re: save hash to file?
by planetscape (Chancellor) on Nov 15, 2010 at 04:45 UTC
|
| [reply] |
Re: save hash to file?
by andreas1234567 (Vicar) on Nov 15, 2010 at 11:34 UTC
|
I would use a human-readable format to store my data, e.g. JSON.
See also this discussion on stackoverflow.com for a comparison of YAML, JSON, XML, Storable.
--
No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]
| [reply] |
Re: save hash to file?
by locked_user sundialsvc4 (Abbot) on Nov 15, 2010 at 14:59 UTC
|
Strictly speaking, your inquiry is ambiguous. The word, “hash,” could mean “a Perl data structure,” or it could mean “(say...) an MD5 or SHA1 digest.”
| |
|
|
| [reply] |
|
|
Not to nit-pick here... :-D ... but if someone were determined to misunderstand the OP, it would still be possible to do so. ;-D
The specific thing that is triggering my uncertainty is the comment, “to use as a search key.” You probably wouldn’t be expecting to use a JSON-string as a search key; but a SHA1 digest, you might.
It’s kinda like the old saw about a computer program finding five different valid parses to the string, “Time flies like an arrow.” You could even parse “save hash to a file” in two different ways: save(hash, to_file) or save(hash(file)).
Aww, heck ... obviously, it is time for more coffee.
TMTOWTCY = There's More Than One Way To Confuse Yourself
| |