mr.nick has asked for the wisdom of the Perl Monks concerning the following question:
So I considered using tie and related functions to store the hash on disk. Of course, you can't have two dimensional hashes via tie. But since my first key is sparse (around 20 entries), I thought I could create a tied hash just for that key, so that the subkey would be on disk.
with the invocation of:sub checkdbm { my $hashref=shift; my $key=shift; if (-f "$key-dbm.db") { return; } tie (%{$hashref->{$key}},'NDBM_File',"$key-dbm",O_RDWR|O_CREAT,0640) +; }
But alas, I can't get it to work. The code executes, the key-dbm.db files are created, but no data is ever stored in it; the program grows in memory until even switching virtual consoles takes minutes to perform.checkdbm \%terms,$db; for my $t (@terms) { $terms{$db}{$t}++; }
Can anyone see what my problem is? (Ahem, my *programming* problem). I suspect I don't understand precisely how tie works and that is biting me in my butt.
TIA!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tie, DBM's, HoH and Sparse Keys
by runrig (Abbot) on Apr 10, 2001 at 22:47 UTC | |
|
Re: Tie, DBM's, HoH and Sparse Keys
by Asim (Hermit) on Apr 10, 2001 at 22:52 UTC | |
by mr.nick (Chaplain) on Apr 10, 2001 at 22:59 UTC | |
|
Re: Tie, DBM's, HoH and Sparse Keys
by jeroenes (Priest) on Apr 11, 2001 at 13:43 UTC | |
|
Re: Tie, DBM's, HoH and Sparse Keys
by TheoPetersen (Priest) on Apr 11, 2001 at 00:13 UTC | |
by mr.nick (Chaplain) on Apr 11, 2001 at 00:17 UTC | |
by TheoPetersen (Priest) on Apr 11, 2001 at 00:24 UTC |