I suggest a key / value database on disk. Thanks to the Perl binding function , they can be used the same way with regular in-memory hashes. They will be faster than Perl read / write hashes if your hash is very large and they automatically save / load to disk.
BerkeleyDB is an old favorite:
use BerkeleyDB; # Make %db an on-disk database stored in database.dbm. Create file if needed tie my %db, 'BerkeleyDB::Hash', -Filename => "database.dbm", -Flags => DB_CREATE or die "Couldn't tie database: $BerkeleyDB::Error"; $db{foo} = 1; # get value print $db{foo}, "\n"; # set value for my $key (keys %db) { print "$key -> $db{$key}\n"; # iterate values } %db = (); # wipe
Changes to the database are automatically saved to disk and will be saved through several calls to your script.
Check perldoc parameters for parameters, but the most important are:
# Increase memory allocation for database (increases performance), eg 640 MB tie my %db, 'BerkeleyDB::Hash', -Filename => $filename, -CacheSize => 640*1024*1024;
A more sophisticated, but much faster database library will be Tokyo Cabinet , and of course there are many other possibilities (after all, this is Perl ...)
source share