Sunday, August 2, 2009

Storable.pm

Most of my programming is what I like to call "biologically driven"; that is the main end result is not the development of the program itself, but rather the data that comes out of the program. Many times this involves writing a script to input data, do something to that data, and then output it back to a file which is in turn read into another script....ad infinitum.

The classic tab-delimited file is usually my typical choice for the intermediate format, but reading and writing (although simple) these gets repetitive and more complicated for more complex data structures. I finally looked into alternatives (something I clearly should have done awhile ago) and came across Storable.

Basically, it allows you to save/open any perl data structure to/from a file.
It is very easy to use:
use Storable;

#Reference to any data structure
$data_ref;

store($data_ref, 'my_storage_file');

#later in same or different script
$new_data_ref = retrieve('my_storage_file');
Check it out if you have never used it before.

3 comments:

Matt Laird said...

But remember to be careful with versions of Storable, the byte order changes between some versions.

We had that problem a year ago when you asked me to install it.

Morgan Langille said...

Yup, I think that scared me away from it for awhile. I also noticed that they have a machine independent format for use on networks/clusters called using nstore.

Neil Cianci said...

I have this issue and need an alternative. Storable might be the right solution. Thanks for the resource.