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};
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^2: short sorts
by Lady_Aleena (Priest) on Mar 30, 2012 at 17:26 UTC

    I'm not certain how the first suggestion would work, so I haven't included it yet. I did use your idea for croak and added it to choroba's observation which I posted at Re^2: short sorts. Thanks! :)

    Have a cookie and a very nice day!
    Lady Aleena