http://qs321.pair.com?node_id=328499

GaijinPunch has asked for the wisdom of the Perl Monks concerning the following question:

This is sucking the life out of me. I've got a big, text file. I go through it, and extract the info i want and stuff it in a hash. There's actually two sets of data though, so I essentially go through the same file twice (it's tied to an array, so this is easy). I specifically
Loop through
Store first set of data in a hash.
Print key-value pairs.
Delete everything in the hash
Repeat.

Most keys share the same label. The values are integers. I even print out the value (and have tried setting them to 0) after deleting to make sure and it looks like they're deleted. However, when I print set B, with the supposedly only set b's data the values are always the sum of the two. (I've confirmed by reversing the order: gathering and printing set b first, then set a. Set b is then "correct" and set a has the sum of the two values for each key).

Below is the subroutine I use to clean out the hash.
sub clean_hash { while ( ( my $key, my $value ) = each %hash ) { + delete $hash{$key}; } }
My other option would be to use dynamic variable names for hashes, but I've read many places that this isn't wise. If anyone can think of anyting I'm missing, I'd love to hear it.