in reply to sort direction
my %hash = ( ... ); my $orderby = "age" # or name, dob, etc my $direction = "ASC" # or DESC foreach my $id ( map { $direction eq "DESC" ? reverse @$_ : @$_ } [ sort { $hash{$a}{$orderby} <=> $hash{$b}{$orderby} || $hash{$a}{$orderby} cmp $hash{$b}{$orderby} } keys %hash ] ) { print "$id - $hash{$id}{$orderby}\n"; } # end-foreach __END__ # my test script: perl -le '@x=(1,4,5,2,3,9,6,8,7); $direction="DESC"; print for map { $ +direction eq "DESC" ? reverse @$_ : @$_ } [sort @x] '
|
|---|