konnjuta has asked for the wisdom of the Perl Monks concerning the following question:
Given list of files delimited by whitespaces and following a format similar to the below example
ID SOURCE SCORE1 SCORE2 SCORE3 ..... SCOREN 66521 SRC1 12 34 27 67 88921 SRC2 34 56 59 88 66524 SRC1 56 66 3341 SRC1 44 59 67
Print out all SRC1 records in reverse column order delimited by a single space and sorted by the last score then sorted by ID.
print join " ", reverse split foreach map { $_->[0] } sort { $a->[1]<=>$b->[1] || $a->[0] <=> $b->[0] } map { [ $_ , (split)[-1] ] } grep { /SRC1/ } <> ;
UPDATE: Here's are possible one-liner solutions thanks to moritz
The Perl 6 syntax is much cleaner.
|
|---|