in reply to Selection of Hash key value pairs

If you have a huge number of elements in the hash, sorting then all can be an expensive and unnecessary operation when only the top 10% or 20% is going to be used later.

In that case, using a heap data structure as implemented by Heap::Simple could be a better solution:

use Heap::Simple; my %data = (...); my $heap = Heap::Simple->new(order => 'gt'); $heap->insert(keys %data); for (1..int(0.1 * keys %data)) { my $key = $heap->extract_top; print "key: $key, value: $data{$key}\n" }