Re: Raku -npe command line usage

2020-05-08 Thread Fernando Santagata
On Fri, May 8, 2020 at 6:10 PM Fernando Santagata wrote: > raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> reduce({$^a ~ "\n" ~ > $^b}) ==> say()' sample.log > and the reduce call can be written more compactly: reduce({"$^a\n$^b"}) -- Fernando Santagata

Re: Raku -npe command line usage

2020-05-08 Thread William Michels via perl6-users
Maybe? perl6 -e 'lines() ==> grep /^WARN/ ==> sort() ==> join("\n") ==> say();' HTH, Bill. On Fri, May 8, 2020 at 9:10 AM Fernando Santagata wrote: > > raku -e'.say for lines() ==> grep(/^WARN/) ==> sort' sample.log > > is not very satisfying because for the "for" which breaks the flow. >

Re: Raku -npe command line usage

2020-05-08 Thread yary
Ooops forgot the sort... let's golf with the hyper-operator again... raku -ne'push my @i: $_ if .starts-with: q[WARN]; END @i.sort>>.say' sample.log -y On Fri, May 8, 2020 at 1:10 PM yary wrote: > ooh neat! I didn't know. Indeed this works. Thanks Sean! > > raku -ne'push my @i: $_ if

Re: Raku -npe command line usage

2020-05-08 Thread yary
ooh neat! I didn't know. Indeed this works. Thanks Sean! raku -ne'push my @i: $_ if .starts-with: q[WARN]; END .say for @i' sample.log -y On Fri, May 8, 2020 at 1:04 PM Sean McAfee wrote: > On Fri, May 8, 2020 at 6:53 AM Brad Gilbert wrote: > >> So together that would be: >> >> raku

Re: Raku -npe command line usage

2020-05-08 Thread Sean McAfee
On Fri, May 8, 2020 at 6:53 AM Brad Gilbert wrote: > So together that would be: > > raku -ne 'BEGIN my @i; @i.push($_) if /^WARN/; END .say for @i.sort' > Or alternately the main body of the loop can be written: (my @i).push($_) if /^WARN/; Or even: push my @i: $_ if /^WARN/;

Re: Raku -npe command line usage

2020-05-08 Thread yary
I like this formulation Fernando posted (removed a set of parens not needed with method calls) raku -e'lines.grep(/^WARN/).sort».say' sample.log It is clean, all left-to-right, and doesn't use "map" for its side-effects only. Putting the feed operator back in where it would work–have to keep

Re: Raku -npe command line usage

2020-05-08 Thread Fernando Santagata
raku -e'.say for lines() ==> grep(/^WARN/) ==> sort' sample.log is not very satisfying because for the "for" which breaks the flow. OTOH this raku -e'lines().grep(/^WARN/).sort».say' sample.log doesn't use the feed operator and this raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> say()'

Re: Raku -npe command line usage

2020-05-08 Thread William Michels via perl6-users
On Fri, May 8, 2020 at 5:16 AM WFB wrote: > > Hi, > > I am trying to write an one-liner to go through all lines in a logfile and > look for an certain key word, store the line and sort them before printing > them out. > > My approach was: > raku -ne "BEGIN {my @i }; @i.push($_); if $_ ~~

Re: Raku -npe command line usage

2020-05-08 Thread Brad Gilbert
The 「@i」 is defined within the 「BEGIN」 block, so it is scoped to the 「BEGIN」 block. If you didn't want that, don't use a *block* with 「BEGIN」. BEGIN my @i; Also you wrote the 「if」 wrong. There shouldn't be a 「;」 before the 「if」. You also don't need to use 「$_ ~~ 」 with 「/^WARN/」 as that