A solution similar to yours in style:
use v6; print join ' ', reverse .words for lines.grep(/SRC1/)\ .map({ [+<<.words[*-1, 0], $_]})\ .sort\ .map(*[2])
And a version using feeds (note that feeds support in Rakudo is still somewhat lacking and experimental, but this one works:)
use v6; lines() ==> grep(/SRC1/) ==> map({ [+<<.words[*-1, 0], $_]}) ==> sort() ==> map(*[2]) ==> my @lines; print ~.words.reverse for @lines;
And here is another solution:
class Line { has $.str handles 'words'; method Str { self.words.reverse.join(' ') } } multi infix:<cmp>(Line $a, Line $b) { $a.words[*-1] <=> $b.words[*-1] || $a.words[0] <=> $b.words[0]; } print lines().map({Line.new(str => $_)}).grep(/SRC1/).sort;
(Which admittedly doesn't do the Schwartz Transform).
(Update: added second version, tested and fixed third version)
In reply to Re: Perl 6 implementation of the following Perl 5 code
by moritz
in thread Perl 6 implementation of the following Perl 5 code
by konnjuta
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |