Problem:
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.
Perl 5 (Possible Solution):
print join " ", reverse split foreach
map { $_->[0] }
sort { $a->[1]<=>$b->[1] || $a->[0] <=> $b->[0] }
map { [ $_ , (split)[-1] ] }
grep { /SRC1/ } <> ;
How can I do it in Perl 6?
UPDATE: Here's are possible one-liner solutions thanks to moritz
Functional Approach
say reverse .words for map *[2], sort map {[.words[*-1,0],$_]}, grep /SRC1/, lines;
Object-Oriented Approach
say .words.reverse for lines.grep(/ICSE/).map({[.words[*-1,0],$_]}).sort.map(*[2]);
The Perl 6 syntax is much cleaner.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.