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

Okay, this just has to be my brain missing something, and it's driving me crazy.

All the following code should be doing is deleting hash keys, not adding them, yes?

print scalar(keys %auto_picks), "\n"; while (my $line = <$sub_fh>) { my @data = split /\t/, $line; if (exists $auto_picks{$data[0]}{$data[1]}) { $auto_picks{$data[0]}{$data[1]} -= $data[2]; if ($auto_picks{$data[0]}{$data[1]} <= 0) { delete $auto_picks{$data[0]}{$data[1]}; if (!keys %{$auto_picks{$data[0]}}) { delete $auto_picks{$data[0]}; } } } } print scalar(keys %auto_picks), "\n";

And yet, based on my data set the first print scalar(keys %auto_picks) returns a little over 100k, and the second more than twice that. Fellow Monks, I implore you, what is the cause of my stupid here?


RESOLVED: Autovivification was my problem and turning it off via the autovivification module was my solution. Thanks to those that pointed out this was my problem.

Just another Perl hooker - My clients appreciate that I keep my code clean but my comments dirty.