in reply to short sorts
If you add the following, right at the top of your sub (inside the curly braces, but before my ($a, $b, $type)...
if (@_ == 2) { my ($type, $ref) = @_; $type =~ s/_/-/g; return sort { short_sorts($a, $b, $type) } @$ref; }
Then it gives you an even shorter syntax for sorting:
my @list = qw(red orange yellow green blue purple); my @sorted = short_sorts ci_a => \@list; print "@sorted\n"; # says "blue green orange purple red yellow"
It's probably also worth adding something like this:
croak "$type is not supported" if $type && !exists $sorts{$type};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: short sorts
by Lady_Aleena (Priest) on Mar 30, 2012 at 17:26 UTC |