Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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.


In reply to Perl 6 implementation of the following Perl 5 code by konnjuta

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (10)
    As of 2014-08-23 13:04 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (173 votes), past polls