Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Classic Sort Algorithm

by Cristoforo (Deacon)
on Jun 21, 2011 at 00:33 UTC ( #910647=note: print w/ replies, xml ) Need Help??


in reply to Classic Sort Algorithm

#!/usr/bin/perl use strict; use warnings; my @x = map {$_->[0]} sort {$b->[2] <=> $a->[2] || $a->[1] <=> $b->[1] } map {[$_, split]} grep {/\S/} <DATA>; for my $i (0 .. $#x) { print $x[$i]; print "\n" if ($i + 1) % 3 == 0; } __DATA__ 1.000 64.103 2840.0 1.000 42.735 2840.0 1.000 32.051 2840.0 1.050 64.103 3280.0 1.050 42.735 3280.0 1.050 32.051 3280.0 1.100 64.103 3720.0 1.100 42.735 3720.0 1.100 32.051 3720.0

prints

1.000 64.103 2840.0 1.050 64.103 3280.0 1.100 64.103 3720.0 1.000 42.735 2840.0 1.050 42.735 3280.0 1.100 42.735 3720.0 1.000 32.051 2840.0 1.050 32.051 3280.0 1.100 32.051 3720.0


Comment on Re: Classic Sort Algorithm
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (12)
As of 2014-08-01 23:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (51 votes), past polls