You have a complex data structure that you want to persist outside your program.
Use MLDBM and either (preferably) DB_File, or else GDBM_File:
use MLDBM qw(DB_File); use Fcntl; tie(%hash, 'MLDBM', 'testfile.db', O_CREAT|O_RDWR, 0666) or die "can't open tie to testfile.db: $!"; # ... act on %hash untie %hash;
A hash with 100,000 items in it would undoubtably take considerable time to build. Storing this to disk, either slowly by hand or quickly with Storable, is still an expensive operation in memory and computation.
The DBM modules solve this by tying hashes to disk database files. Rather than reading the whole structure in at once, they only pull in what they need, when they need it. To the user, it looks like a hash that persists across program invocations.
Unfortunately, the values in this persistent hash must be plain strings. You cannot readily use a database file as a backing store for a hash of hashes, a hash of arrays, and so on, just for a hash of strings.
However, the MLDBM module from CPAN allows you to store references in a database. It uses Data::Dumper to stringify these references for external storage:
use MLDBM qw(DB_File); use Fcntl; tie(%hash, 'MLDBM', 'testfile.db', O_CREAT|O_RDWR, 0666) or die "can't open tie to testfile.db: $!";
Now you can use