in reply to Sorting question
Maybe a dispatch table would help.
sub thing { my ( $ref, $sort_by ) = @_; my %sort_sub = ( thing1 => sub { $ref->{$a} <=> $ref->{$b} }, thing2 => sub { $ref->{$a}->[CON] <=> $ref->{$b}->[CON] }, etc => sub { 'and so forth' }, ); my $sorter = $sort_sub{$sort_by}; for my $key ( sort $sorter keys %{$ref} ) { # ... } }
Then you call it as thing( $ref, 'thing1' ), for example.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sorting question (sort ($$))
by lodin (Hermit) on Feb 13, 2008 at 00:53 UTC |