in reply to Re: hash function
in thread hash function

Data::Dumper works just fine on Tied hashs.
use strict; use warnings; use Data::Dumper; use DB_File; my %words; tie %words, 'DB_File', 'words.db'; load() if $ARGV[0]; print Dumper \%words; sub load { my $cnt = 1; foreach my $key ( 'John Cleese', 'Graham Chapman', 'Eric Idle', 'Ter +ry Jones', 'Michael Palin') { $words{$key} = "Gumby $cnt"; $cnt++; } }


grep
One dead unjugged rabbit fish later

Replies are listed 'Best First'.
Re^3: hash function
by graff (Chancellor) on Oct 07, 2006 at 19:33 UTC
    But... what if the DB file is really big? (Sometimes people tie a hash to a DB file because of the amount of data, not just for persistence.) When I tried the following test:
    perl -MDB_File -MData::Dumper -e 'tie %h, "DB_File", "junk.db"; for ($i=0; $i<1_000_000; $i++) { $h{"key_$i"}="value_$i" }; warn "the hash is loaded\n"; sleep 15; warn "starting dump\n"; print Dumper(\%h); warn "the hash has been dumped\n"; sleep 15' > /dev +/null
    Memory usage stayed at about 27 MB (macosx/perl 5.8.6) while the hash was being built and throughout the first sleep, then climbed over 450 MB during the Dump phase. Data::Dumper was making its own internal copies of the keys and values.

    (The "junk.db" file itself was 47 MB, and a plain-text print out of keys and values as I suggested above would probably be about half that.)