|Perl: the Markov chain saw|
Clean out da hash...by GaijinPunch (Pilgrim)
|on Feb 12, 2004 at 08:04 UTC||Need Help??|
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
Store first set of data in a hash.
Print key-value pairs.
Delete everything in the hash
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.
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.