in reply to Re: hash on memory or disk?
in thread hash on memory or disk?

Does this test for an empty hash use a lot of memory if the hash is big?
$nmail->relay('<>',1) unless keys %$hash_ref;

Replies are listed 'Best First'.
Re: hash on memory or disk?
by Abigail-II (Bishop) on Jan 14, 2004 at 11:30 UTC
    No, keys in scalar context just returns the number of elements of the hash; and the hash keeps score in its internal datastructure.

    This is of course assuming we are talking about a normal hash. If the hash is tied, then it will depend on the implementation.

    Abigail

      Thanks for your reply.

      I have managed to reduce some of the memory usage (because I'm able to process more of the log now) but my program is still crashing. I'm having a problem tying the hashes whose elements are arrays e.g.

      tie %recipientqids, 'MLDBM', "/home/u752359/recipientqids.db", O_CREAT +|O_RDWR, 0640 or die $!; push(@{$recipientqids{$hostqid}},$recipient); .. .. foreach $hostqid( @{$msgidqids{$msgid}}){ foreach $recipient (@{$recipientqids{$hostqid}}){ print STDERR "\nrecip= $recipient"; } }

      doesn't print anything if I tie the recipientqids hash.

      Is my syntax wrong, or can you not store these structures with MLDBM?

      Thanks,

      js1