[Omaha.pm] sort hackery

Jay Hannah jhannah at omnihotels.com
Tue Oct 25 08:43:13 PDT 2005


So I've got this array of hashrefs that was built like this:

   push @arr, { code=>$prop, desc=>$desc, };

And I want to sort them alphabetically based of desc.

So I do this:

  # Sort the list by descriptions
  @arr = sort sort_by_desc @arr;

  sub sort_by_desc {
     $a->{desc} cmp $b->{desc}; 
  }

And it worked, 2nd try. 

Yay! It appears I've learned a little Perl over the years. -grin-

Custom sorting methods in Perl rule. Do any other languages allow you to
define custom arbitrary sorting rulesets so easily?

j



More information about the Omaha-pm mailing list