in reply to Improving sorts using ST

That's not really a complicated sort. Here's one way of doing it using ST:
@sorted_array = map {$_ -> [0]} sort {$a -> [1] <=> $b -> [1]} map {[$_ => (split /$delim/ => $_) [$key]]} @$array_2_ +sort_ref;
For the non-numeric sort, replace <=> with cmp.

You are mistaken however that ST allows more complex sorting. There's nothing ST can sort that you can't sort with a non-ST method. ST can be more efficient though. However, a GRT often beats an ST when it comes to efficiency.

Abigail

Replies are listed 'Best First'.
Re: Re: Improving sorts using ST
by drewbie (Chaplain) on May 20, 2004 at 17:45 UTC
    Uri Guttman has written Sort::Maker (not yet on CPAN) which will help build the different types of sorts for those who want to build them on the fly. He just gave a talk about it at the boston.pm meeting Tuesday and IIRC he's going to be talking about it at YAPC::NA this year. The talk (and some of the module POD also) focuses a bit on when and why you would use the different types of sorts.
      This should be very interesting once available.

      Thanks!

      Sweetblood

Re: Re: Improving sorts using ST
by sweetblood (Prior) on May 20, 2004 at 14:57 UTC
    Hmmm, that gives me more to think about.(I like that)
    Still, I'm having trouble understanding how to do this sort on mutltiple fields.

    Thanks agian!

    Sweetblood