in reply to sort direction

It seems to me that you might be able to do a little glob magic. And it's really more of a clever-for-fun idea than a recommended coding technique. I can't test it, so it probably needs some adjustments, but the idea should be pretty clear.
sub mysort { $hash{$a}{$orderby} <=> $hash{$b}{$orderby} or $hash{$a}{$orderby} cmp $hash{$b}{$orderby} } { local (*a, *b) = ($direction eq 'DESC') ? (\*b, \*a) : (\*a, \*b); foreach my $id (sort mysort keys %hash) { print "$id - $hash{$id}{$orderby}\n"; } }

Caution: Contents may have been coded under pressure.