Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

•Re: Complex Sort - using varying numbers of parameters

by merlyn (Sage)
on Jul 04, 2002 at 14:54 UTC ( #179470=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://179470]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2021-08-02 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (28 votes). Check out past polls.

    Notices?