<?xml version="1.0" encoding="windows-1252"?>
<node id="962140" title="Re: short sorts" created="2012-03-28 06:20:54" updated="2012-03-28 06:20:54">
<type id="11">
note</type>
<author id="757127">
tobyink</author>
<data>
<field name="doctext">
&lt;p&gt;If you add the following, right at the top of your sub (inside the curly braces, but before &lt;c&gt;my ($a, $b, $type)&lt;/c&gt;...&lt;/p&gt;

&lt;code&gt;
  if (@_ == 2) {
    my ($type, $ref) = @_;
    $type =~ s/_/-/g;
    return sort { short_sorts($a, $b, $type) } @$ref;
  }
&lt;/code&gt;

&lt;p&gt;Then it gives you an even shorter syntax for sorting:&lt;/p&gt;

&lt;code&gt;
 my @list = qw(red orange yellow green blue purple);
 my @sorted = short_sorts ci_a =&gt; \@list;
 print "@sorted\n";
 # says "blue green orange purple red yellow"
&lt;/code&gt;

&lt;p&gt;It's probably also worth adding something like this:&lt;/p&gt;

&lt;code&gt;
croak "$type is not supported"
  if $type &amp;&amp; !exists $sorts{$type};
&lt;/code&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-757127"&gt;
&lt;small&gt;&lt;small&gt;
&lt;tt&gt;perl -E'sub Monkey::do{say$_,for@_,do{($monkey=&amp;#x5B;caller(0)]-&gt;&amp;#x5B;3])=~s{::}{ }and$monkey}}"Monkey say"-&gt;Monkey::do'
&lt;/tt&gt;&lt;/small&gt;&lt;/small&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
962078</field>
<field name="parent_node">
962078</field>
</data>
</node>
