Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Complex Sort - using varying numbers of parameters

by Courage (Parson)
on Jul 04, 2002 at 12:40 UTC ( [id://179444]=note: print w/replies, xml ) Need Help??


in reply to Complex Sort - using varying numbers of parameters

Following code seems to work for me:
my @arr = map {[split /\s+/]} <DATA>; sub criteria { my $r = 0; $r ||= (($a->[$_]||0) <=> ($b->[$_]||0)) for 0..5; $r; } @arr = sort {criteria} @arr; print join "\n", map {join " ", @$_} @arr; __DATA__
This could be optimized to return from 0..5 loop earlier, and sub could be inlined, but let's do this another time.

Courage, the Cowardly Dog

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-23 17:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found