Update: do the hash lookup only once, not for every comparison.my %sorts = ( DESC => sub { $hash{$b}{$orderby} <=> $hash{$a}{$orderby} or $hash{$b}{$orderby} cmp $hash{$a}{$orderby} }, ASC => sub { $hash{$a}{$orderby} <=> $hash{$b}{$orderby} or $hash{$a}{$orderby} cmp $hash{$b}{$orderby} } ); my $sort_func = $sorts{$direction}; foreach my $id (sort { &$sort_func } keys %hash) {
In reply to Re^2: sort direction
by Roy Johnson
in thread sort direction
by rsiedl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |