in reply to Re: How do I keep the first key in a sorted hash?
in thread How do I keep the first key in a sorted hash?

If your hash is large, then using the sort function just to retrieve the smallest value is inefficient overkill. Use a variable, say $min, and set it to any key that you know to exist (or to a very large value such as 1e10 that you know will larger than at least one of the keys). Then you can simply do something like this:
my $min = 1e10; for my $key (keys %h) { $min = $key if $key < $min; } # now, $min is the smallest key. The associated value is simply $h{$mi +n}
Now, depending on how you get the data in the first place, you could also maintain the $min variable when populating the hash, thereby avoiding to read all the keys once more.