my $sort_by = 'age'; my $descending = 1; my $database = \%people; # return an ordered list of copies of keys of a # hash structured as described somewhere # usage: sort_people( \%sort_me, $by_me, $descending ) # Ascending sort is the default. # If $by_me is not a key that exists then ... # Maybe an arref should be returned. sub sort_people { my ( $people, $by, $desc) = @_; no warnings qw/ numeric uninitialized/; if ( $desc) { return sort { your_conditions( $b, $a)} keys %$people; } else { return sort { your_conditions( $a, $b)} keys %$people; } }