One may not know the minimum & maximum values without inspecting to use range operator, so ...
use strict; use warnings;
use List::MoreUtils 'minmax';
my %hash = ( ... );
# Absurdity is to find end values in order to avoid
# numeric comparison.
my ( $min , $max ) = minmax keys %hash;
for my $i ( $min .. $max )
Yes, this is indeed a "bad way" to do it! Compared with sort(), this will be slow (20..99) yield no result and it doesn't scale well. And I guess that you would in the general case, have to read every key to find the maximum key value.