Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Perl 6 implementation of the following Perl 5 code

by konnjuta (Acolyte)
on May 28, 2013 at 00:34 UTC ( #1035488=note: print w/ replies, xml ) Need Help??


in reply to Re: Perl 6 implementation of the following Perl 5 code
in thread Perl 6 implementation of the following Perl 5 code

The 1st/2nd Perl 6 solution is interesting because you read it from left to right treating map,grep and sort as object methods.

The Perl 5 version is read from right to left treating map,grep and sort as functions. I've attempted to do it the functional way in Perl 6 and got the following to work on Rakudo.

use v6; say reverse .words for map {.[1]} ,sort( map { [.words[*-1],$_] } ,grep {/SRC1/} ,lines() );

The syntax for doing Perl 6 functionally seems to be more untidy than the Perl 5 version and make it a bit harder to read. The required comma, the required parenthesis around sort. Its not too bad though. Will get some getting use to.


Comment on Re^2: Perl 6 implementation of the following Perl 5 code
Download Code
Re^3: Perl 6 implementation of the following Perl 5 code
by moritz (Cardinal) on May 28, 2013 at 05:26 UTC

    If you make the commas stand out by putting them up front, it looks untidy, yes. As they say, the key is to play to Perl's strengths, not to its weaknesses.

    And if you include unnecessary punctuation, it also looks untidy. This one seems to work fine:

    use v6; say reverse .words for map *[1], sort map { [.words[*-1],$_] }, grep /SRC1/, lines;

      I can confirm this works and Infact its actually much cleaner for people who likes one-liner

      say reverse .words for map *[1], sort map {[.words[*-1],$_]}, grep /ICSE/, lines;

      Hmm ... now I'm wondering why I couldn't get the sort to work without the parenthesis previously.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2014-07-29 05:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls