in reply to
Tie data hash to DBM file leaving massive cruft?
I haven't been able to find a specification of the dbm file format, so I can only guess. It could be either an artifact of storage format (some sort of tree), or it could be that instead of deleting entries, they are simply marked as deleted.
One way to find out is compare a copy of the file you produce now with the another you get from inserting all the key/value pairs into an empty file.
In fact I guess it's more efficient anyway to simply unlink the file instead of opening it, emptying it and then refilling it.