Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Complex Sort - using varying numbers of parameters

by Courage (Parson)
on Jul 04, 2002 at 12:40 UTC ( #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? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2021-07-30 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?