What is the Storable module used for?
I am having a hard t开发者_开发百科ime 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?
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 torequire
a file containingData::Dump
output
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.
精彩评论