in reply to Re: Re: rebuilding hashes
in thread rebuilding hashes

As Abigail-II said, you never do anything that would delete the {4} key. Assigning its value to the {3} key doesn't affect {4}.

A crude way to fix it: After your reassignment loop, delete keys until there are only 1 + (original)$num.

my $to_delete = keys(%hash) - $num+1; while ($to_delete) { --$to_delete if defined delete $hash{++$num}; }