...I can see what's going on here very clearly. The data is being stored in a hash using keys which are expected to be sequentially numbered integers. Or in simpler terms, we're taking a hash and making it perform as an array.
But, as others point out here, if the hash is initialized (or manipulated) in an unexpected way, the scheme breaks down.
Not to be glib, but...
I eat my peas with honey.
I've done it all my life.
It makes the peas taste funny.
But it keeps them on the knife.
Unless there's some rationale that is not clear from the original code snippet, I'd say use an array instead of a hash. Then push() will reduce the amount of logic required to get your information into the data structure.
...All the world looks like -well- all the world,
when your hammer is Perl.
---v