in reply to Complex Sort - using varying numbers of parameters

I saw a few GRTs, and a few awkward Schwartzian Transforms, so I thought I'd throw my own in:
my @sorted = map $_->[0], sort { for (1..1000) { return @$a <=> @$b if $_ > $#$a or $_ > $#$b; $_ and return $_ for $a->[$_] <=> $b->[$_]; } } map [$_, split /\s+/], @inputdata;
Presumes less than 1000 sort fields. Probably reasonable.

-- Randal L. Schwartz, Perl hacker


updated to reflect a few missing dollar signs and a brain confusion in a pre-caffiene state. {sigh}

Replies are listed 'Best First'.
Re: Complex Sort - using varying numbers of parameters
by Abigail-II (Bishop) on Jul 04, 2002 at 15:04 UTC
    Next time, test your code. It doesn't even want to compile with 'use strict', and produces rubbish otherwise. Here's a tested version:
    my @sorted = map $_->[0], sort { for (1..1000) { return @$a <=> @$b if $_ > $#$a or $_ > $#$b; $_ and return $_ for $a->[$_] <=> $b->[$_]; } } map [$_, split /\s+/], @inputdata;
    BTW, what's a GSR?

    Abigail