Perl DBM vs. Storable

♀尐吖头ヾ 提交于 2019-12-12 13:28:17

问题


for my current project i need to store a little database on disk, that i read once my program runs and write it once.

I have looked into perls DBM functionality and from what I understand it provides merely a hash that is stored on disk with every read and write going directly to disk.

My question is: Could I not simply use Storable or any of the related modules to achieve the same (a persistent hash) with far less File I/O overhead? (The hashes will never be to large to fit into memory easily)

Regards Nick


回答1:


SQLite is fast becoming the standard for simple on-disk databases. And in Perl you can just use DBD::SQLite and you're good to go.




回答2:


Since the previous answers didn't really answer your actual question, "yes, you can"... with the following caveats:

  • Storable isn't really suited to concurrent access.
  • You will need to roll your own "atomic" update (ie: you will need to write to a tmp file, then rename).
  • If performance isn't really an issue, you could also use Data::Dumper (with the resulting file being somewhat human readable).
  • You could splat the contents to CSV.

I often use Dumper when there is only going to be a single task accessing the file - and it gives me a way to read/modify the contents if I see fit.



来源:https://stackoverflow.com/questions/8680241/perl-dbm-vs-storable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!