问题
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