in reply to Devel::Size reports different size after hash access

The problem is that you are using the numeric values of the hash in a string context: print $fh "$key $hash{$key}\n";; thus perl converts what were IVs (internal integers) into PVs (internal strings), caching the result in the expectation you might use them in a string context again.

As an IV, each value requires 24 bytes, but once converted to a string and stored in a PV, each value requires ~56 bytes.

You can avoid the conversion being cached by making perl convert a temporary value to a string for printing like this:

printf $fh "$key %d\n", 0+$hash{$key};

That will avoid the memory growth.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.