[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] File::Sort



Brian wrote:
>Chris Nandor writes:
>|And this module really makes me wish I could pass a coderef to sort(); that
>|would make it much easier to incorporate different ordering schemes.  Any
>|thoughts on that?
>

>$r = sub { $a cmp $b };
>sort {&$r} @array;

This causes a lot more overhead than you probably want a sorting
routine to have. It has to dereference $r on each compare. You can
work around it by using typeglobs:

{
  local(*sortsub) = $r; # temporarily give the code $r have the name "sortsub"
  sort sortsub @array;
}



-- 
Andrew Langmead

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch