in reply to Re^2: How to add missing part in a Hash of Array
in thread How to add missing part in a Hash of Array

You might have read it too quickly, but Athanasius's solution does not rely in any way on finding the range of missing positions, but only on knowing the current lowest and highest valid (i.e. defined) positions in the hash (i.e. smallest and highest keys). It is quite easy to find them, using the min and max functions of the List::Utils module or rolling out your own algorithm to do it:
my ($min, $max) = (1e10, -1e10); for my $value (keys %hash) { $min = $value if $value < $min; $max = $value if $value > $max; } # $now $min has the smallest key and $max the highest one
Or, if your data is small, you could possibly even use the sort function to do it in one single instruction:
my ($min, $max) = (sort {$a<=>$b} keys %hash)[0,-1];
But that's getting quickly rather inefficient when the data is growing.