Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

RE: Dynamic sort algorithm selection

by Fastolfe (Vicar)
on Nov 15, 2000 at 19:10 UTC ( [id://41771] : note . print w/replies, xml ) Need Help??


in reply to Dynamic sort algorithm selection

I might implement that something like this:
%SORT_INFO = ( 'firstname' => sub { $a->{FirstName} cmp $b->{FirstName} }, 'firstname_desc => sub { $b->{FirstName} cmp $a->{FirstName} }, ... ); ... if (exists $SORT_INFO{param('sort_by')}) { @sorted = sort $SORT_INFO{param('sort_by')} @unsorted; } elsif (param('sort_by')) { die "Unknown sort_by item: " . param('sort_by'); } else { @sorted = @unsorted; }