What is the Storable module used for?

853 Views Asked by At

I am having a hard time understanding what Storable does.

I know that it "stores" a variable into your disk, but why would I need to do that? What would I use this module for, and how would I do it?

2

There are 2 best solutions below

1
On BEST ANSWER

Reasons that spring to mind:

  • Persist memory across script calls
  • Sharing variables across different processes (sometimes it isn't possible to pipe stuff)

Of course, that's not all that Storable does. It also:

  • Makes it possible to create deep clones of data structures
  • Serializes the data structure stored, which implies a smaller file footprint than output from Data::Dump
  • Is optimized for speed (so it's faster to retrieve than to require a file containing Data::Dump output
9
On

One example:

Your program spends a long time populating your data structure, a graph, or trie, and if the program crashes then you'd lose it all and have to start again from square one. To avoid losing this data and be able to continue where it stopped last time you can save a snapshot of the data to a file manually or just simply use Storable.