开发者

What is the Storable module used for?

开发者 https://www.devze.com 2023-03-30 06:52 出处:网络
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 ho

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 to require a file containing Data::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.

0

精彩评论

暂无评论...
验证码 换一张
取 消