in reply to Saving a hash/array to a file
While AM mentioned using a DB, a very simple way to save a hash/array to a file, is to use a 'foreach' or 'for' loop on the hash or array and print the contents to a file. When you need the hash/array again just use the same technique in reverse.
You don't mention the type of data, but if it's ASCII text, you can use the tab character (\t) between the key and value with the normal carriage return (\n) to end the value field.
But since it's speed you require, I would use the unbuffered 'sysopen/sysread/syswrite'.
To generate the file, use the same loop technique to build a large string of the complete hash/array and then 'syswrite' the string to disk as one operation. To get the hash/array use 'sysread' to get the string back into memory. Then use 'split' to get back your hash/array. Depending on hardware you can get 5 times or more improvement in speed. If using Linux, use the '/dev/shm' Filesystem for saving the string with improved performance ( if your memory is large enough?).
Obviously, if the string is too large for memory, then you will need to use a DB and 'BerkeleyDB' is a good choice.
Regards...Ed
"Well done is better than well said." - Benjamin Franklin
|
|---|