develooper Front page | perl.perl6.language | Postings from February 2004

Re: The Sort Problem

Thread Previous | Thread Next
From:
Uri Guttman
Date:
February 14, 2004 13:24
Subject:
Re: The Sort Problem
Message ID:
x77jypbbtt.fsf@mail.sysarch.com
>>>>> "AH" == Austin Hastings <austin_hastings@yahoo.com> writes:

  AH> --- Uri Guttman <uri@stemsystems.com> wrote:
  >> @out = sort
  >> key:compare( \&my_compare_sub ) ( /(\d+)$/ ),
  >> @in ;

  >> note that the custome compare callbacks can be a block or a sub
  >> name/ref. the callback sub would be passed 2 args as usual.

  AH> Off the top of my head, I can't think of a case where the compare sub
  AH> would be needed unless the key was not well-ordered. Does anyone have
  AH> an example of a case where the key-extraction sub approach doesn't
  AH> reduce the problem to a Scalar comparison? 

there are rare times when you need a computed comparison, say with a
specialized collation sequence. if this sequence isn't supported by
locale or whatever, you need to do a callback comparison. i can't think
of a real world example but maybe with some odd symbolic character set
or a custom one. in any case, supporting the callback is easy. it has
one drawback which is that it disallows the GRT but the guts could
fallback to the ST then. in both cases, key extraction is the same.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About