Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Comment on

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


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],$_]})*[2]);

The Perl 6 syntax is much cleaner.

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

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!
  • 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, 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (1)
    As of 2018-05-27 23:54 GMT
    Find Nodes?
      Voting Booth?