Re: Raku -npe command line usage

2020-05-08 Thread WFB
Uh, just stand up and having 16 answers in my inbox :-) Thanks guys!

The : mistake was because I did not copy instead I wrote it and put
the : in there accidentally.
The curly braces for the phasers was the issue. But I though phasers are
written this way like IF clauses are. I already saw braceless phasers, but
thought that is the same as IF which can also be written without them.

Learned a lot, thanks a lot!
Wolfgang


On Sat, 9 May 2020 at 01:33, yary  wrote:

> The comma is more boring than that, it's simply separating the arguments
> to the sub "grep" - adding parend
>
> .say for sort grep( *.starts-with(q[WARN]), lines )
>
> grep as a sub takes a routine as the 1st arg, and the list to grep
> through after.
>
> -y
>
>
> On Fri, May 8, 2020 at 7:28 PM William Michels 
> wrote:
>
>> >Boring hard-to-read solution not using any of those
>> > raku -e'.say for sort grep *.starts-with(q[WARN]),lines' sample.log
>>
>> Interesting! I don't think I've seen a comma used like that in a
>> one-liner. Also a very fast solution (thanks Brad!).
>>
>> Presumably the ",lines" tells raku/perl6 to run the preceding code on
>> input lines?
>>
>> TIA, Bill.
>>
>> On Fri, May 8, 2020 at 11:03 AM yary  wrote:
>> >
>> > > perl6 -e 'lines() ==> grep /^WARN/ ==> sort() ==> join("\n") ==>
>> say();'
>> >
>> > that's neat too.
>> >
>> > This is showed me that I didn't have a clear grasp of the feed operator
>> ==> vs the hyper-operator >>
>> >
>> > Now I have learned/internalized that the feed operators pass along the
>> entire sequence (list?), whereas the hyper-operator passes items one at a
>> time. Hence "==> say" putting the results on one line, because "say" is
>> getting the entire list. And  ">>.sort" not sorting, because sort would be
>> called once per item with only that single item to sort.
>> >
>> > Boring hard-to-read solution not using any of those
>> >
>> > raku -e'.say for sort grep *.starts-with(q[WARN]),lines' sample.log
>> >
>> > -y
>> >
>> > On Fri, May 8, 2020 at 1:20 PM William Michels 
>> wrote:
>> >>
>> >> 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.
>> >> > 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()' sample.log
>> >> >
>> >> > outputs a list on one line, not each line on its own. This one
>> works, but it feels awkward:
>> >> >
>> >> > raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> reduce({$^a ~ "\n"
>> ~ $^b}) ==> say()' sample.log
>> >> >
>> >> > On Fri, May 8, 2020 at 5:49 PM yary  wrote:
>> >> >>
>> >> >> All good ideas so far, in the "more than one way to do it" spirit,
>> can use "state" instead of "my", since state only initializes 1st time it's
>> hit.
>> >> >>
>> >> >> raku -ne 'state @i;@i.push($_) if .starts-with(q[WARN]); END
>> .say for @i.sort' sample.log
>> >> >>
>> >> >> Or adapting Brad's answer with the feed operator for fun
>> >> >>
>> >> >> raku -e 'for lines() ==> grep /^WARN/ ==> sort() {.say}'
>> sample.log
>> >> >>
>> >> >> Now, I didn't want to use 'map' in there, because of a habit of
>> only using 'map' when I want the return values. When looping for
>> side-effects only, like saying each value in a list, I want to use 'for'.
>> UnFORtunately though I cannot find anything as clean looking as
>> >> >>
>> >> >> raku -e 'lines() ==> grep /^WARN/ ==> sort() ==> map *.say'
>> sample.log
>> >> >>
>> >> >> reading entirely L-to-R which does NOT use map... ideas?
>> >> >>
>> >> >> -y
>> >> >>
>> >> >>
>> >> >> On Fri, May 8, 2020 at 10:10 AM William Michels via perl6-users <
>> perl6-us...@perl.org> wrote:
>> >> >> >
>> >> >> > 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 $_ ~~ /^WARN/; END {
>> @i.sort.say }"
>> >> >> > > That does not work because @i does not exist in the if clause.
>> I tried our @i as well with no luck.
>> >> >> > >
>> >> >> > > How can I store data that can be accessed in the END phaser? Or
>> is there another way to archive it? TIMTOWTDI^^
>> >> >> > >
>> >> >> > > One hint I found was the variable $ and @ respectively. But
>> those variables are created for each line new...
>> >> >> > >
>> >> >> > >
>> >> >> > > I did not found a help or examples for -npe except raku -h. Is
>> there more helpful stuff somewhere in doc.raku.org? If so I could'nt
>> 

Re: Raku -npe command line usage

2020-05-08 Thread yary
The comma is more boring than that, it's simply separating the arguments to
the sub "grep" - adding parend

.say for sort grep( *.starts-with(q[WARN]), lines )

grep as a sub takes a routine as the 1st arg, and the list to grep
through after.

-y


On Fri, May 8, 2020 at 7:28 PM William Michels 
wrote:

> >Boring hard-to-read solution not using any of those
> > raku -e'.say for sort grep *.starts-with(q[WARN]),lines' sample.log
>
> Interesting! I don't think I've seen a comma used like that in a
> one-liner. Also a very fast solution (thanks Brad!).
>
> Presumably the ",lines" tells raku/perl6 to run the preceding code on
> input lines?
>
> TIA, Bill.
>
> On Fri, May 8, 2020 at 11:03 AM yary  wrote:
> >
> > > perl6 -e 'lines() ==> grep /^WARN/ ==> sort() ==> join("\n") ==>
> say();'
> >
> > that's neat too.
> >
> > This is showed me that I didn't have a clear grasp of the feed operator
> ==> vs the hyper-operator >>
> >
> > Now I have learned/internalized that the feed operators pass along the
> entire sequence (list?), whereas the hyper-operator passes items one at a
> time. Hence "==> say" putting the results on one line, because "say" is
> getting the entire list. And  ">>.sort" not sorting, because sort would be
> called once per item with only that single item to sort.
> >
> > Boring hard-to-read solution not using any of those
> >
> > raku -e'.say for sort grep *.starts-with(q[WARN]),lines' sample.log
> >
> > -y
> >
> > On Fri, May 8, 2020 at 1:20 PM William Michels 
> wrote:
> >>
> >> 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.
> >> > 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()' sample.log
> >> >
> >> > outputs a list on one line, not each line on its own. This one works,
> but it feels awkward:
> >> >
> >> > raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> reduce({$^a ~ "\n" ~
> $^b}) ==> say()' sample.log
> >> >
> >> > On Fri, May 8, 2020 at 5:49 PM yary  wrote:
> >> >>
> >> >> All good ideas so far, in the "more than one way to do it" spirit,
> can use "state" instead of "my", since state only initializes 1st time it's
> hit.
> >> >>
> >> >> raku -ne 'state @i;@i.push($_) if .starts-with(q[WARN]); END
> .say for @i.sort' sample.log
> >> >>
> >> >> Or adapting Brad's answer with the feed operator for fun
> >> >>
> >> >> raku -e 'for lines() ==> grep /^WARN/ ==> sort() {.say}'
> sample.log
> >> >>
> >> >> Now, I didn't want to use 'map' in there, because of a habit of only
> using 'map' when I want the return values. When looping for side-effects
> only, like saying each value in a list, I want to use 'for'. UnFORtunately
> though I cannot find anything as clean looking as
> >> >>
> >> >> raku -e 'lines() ==> grep /^WARN/ ==> sort() ==> map *.say'
> sample.log
> >> >>
> >> >> reading entirely L-to-R which does NOT use map... ideas?
> >> >>
> >> >> -y
> >> >>
> >> >>
> >> >> On Fri, May 8, 2020 at 10:10 AM William Michels via perl6-users <
> perl6-us...@perl.org> wrote:
> >> >> >
> >> >> > 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 $_ ~~ /^WARN/; END {
> @i.sort.say }"
> >> >> > > That does not work because @i does not exist in the if clause. I
> tried our @i as well with no luck.
> >> >> > >
> >> >> > > How can I store data that can be accessed in the END phaser? Or
> is there another way to archive it? TIMTOWTDI^^
> >> >> > >
> >> >> > > One hint I found was the variable $ and @ respectively. But
> those variables are created for each line new...
> >> >> > >
> >> >> > >
> >> >> > > I did not found a help or examples for -npe except raku -h. Is
> there more helpful stuff somewhere in doc.raku.org? If so I could'nt find
> it.
> >> >> > >
> >> >> > > Thanks,
> >> >> > > Wolfgang
> >> >> >
> >> >> > Hi Wolfgang,
> >> >> >
> >> >> > This is a first attempt at doing what you want: I'm sure it can be
> >> >> > shortened. Since one of your requirements is doing a sort on
> filtered
> >> >> > values stored in an array, I abandoned use of the "-ne" one-liner
> >> >> > flag, using "-e"  and "for lines()" instead. I also used grep
> instead
> >> >> > of smart-matching:
> >> >> >
> >> >> > perl6 -e 'my @i; for lines() {if .grep(/^WARN/) -> ($s)
> >> >> > {@i.push($s)};}; .say for @i.sort;'
> >> >> >
> >> >> > Note: the "-> ($s)" 

Re: Raku -npe command line usage

2020-05-08 Thread William Michels via perl6-users
>Boring hard-to-read solution not using any of those
> raku -e'.say for sort grep *.starts-with(q[WARN]),lines' sample.log

Interesting! I don't think I've seen a comma used like that in a
one-liner. Also a very fast solution (thanks Brad!).

Presumably the ",lines" tells raku/perl6 to run the preceding code on
input lines?

TIA, Bill.

On Fri, May 8, 2020 at 11:03 AM yary  wrote:
>
> > perl6 -e 'lines() ==> grep /^WARN/ ==> sort() ==> join("\n") ==> say();'
>
> that's neat too.
>
> This is showed me that I didn't have a clear grasp of the feed operator ==> 
> vs the hyper-operator >>
>
> Now I have learned/internalized that the feed operators pass along the entire 
> sequence (list?), whereas the hyper-operator passes items one at a time. 
> Hence "==> say" putting the results on one line, because "say" is getting the 
> entire list. And  ">>.sort" not sorting, because sort would be called once 
> per item with only that single item to sort.
>
> Boring hard-to-read solution not using any of those
>
> raku -e'.say for sort grep *.starts-with(q[WARN]),lines' sample.log
>
> -y
>
> On Fri, May 8, 2020 at 1:20 PM William Michels  wrote:
>>
>> 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.
>> > 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()' sample.log
>> >
>> > outputs a list on one line, not each line on its own. This one works, but 
>> > it feels awkward:
>> >
>> > raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> reduce({$^a ~ "\n" ~ 
>> > $^b}) ==> say()' sample.log
>> >
>> > On Fri, May 8, 2020 at 5:49 PM yary  wrote:
>> >>
>> >> All good ideas so far, in the "more than one way to do it" spirit, can 
>> >> use "state" instead of "my", since state only initializes 1st time it's 
>> >> hit.
>> >>
>> >> raku -ne 'state @i;@i.push($_) if .starts-with(q[WARN]); END .say for 
>> >> @i.sort' sample.log
>> >>
>> >> Or adapting Brad's answer with the feed operator for fun
>> >>
>> >> raku -e 'for lines() ==> grep /^WARN/ ==> sort() {.say}' sample.log
>> >>
>> >> Now, I didn't want to use 'map' in there, because of a habit of only 
>> >> using 'map' when I want the return values. When looping for side-effects 
>> >> only, like saying each value in a list, I want to use 'for'. 
>> >> UnFORtunately though I cannot find anything as clean looking as
>> >>
>> >> raku -e 'lines() ==> grep /^WARN/ ==> sort() ==> map *.say' sample.log
>> >>
>> >> reading entirely L-to-R which does NOT use map... ideas?
>> >>
>> >> -y
>> >>
>> >>
>> >> On Fri, May 8, 2020 at 10:10 AM William Michels via perl6-users 
>> >>  wrote:
>> >> >
>> >> > 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 $_ ~~ /^WARN/; END { 
>> >> > > @i.sort.say }"
>> >> > > That does not work because @i does not exist in the if clause. I 
>> >> > > tried our @i as well with no luck.
>> >> > >
>> >> > > How can I store data that can be accessed in the END phaser? Or is 
>> >> > > there another way to archive it? TIMTOWTDI^^
>> >> > >
>> >> > > One hint I found was the variable $ and @ respectively. But those 
>> >> > > variables are created for each line new...
>> >> > >
>> >> > >
>> >> > > I did not found a help or examples for -npe except raku -h. Is there 
>> >> > > more helpful stuff somewhere in doc.raku.org? If so I could'nt find 
>> >> > > it.
>> >> > >
>> >> > > Thanks,
>> >> > > Wolfgang
>> >> >
>> >> > Hi Wolfgang,
>> >> >
>> >> > This is a first attempt at doing what you want: I'm sure it can be
>> >> > shortened. Since one of your requirements is doing a sort on filtered
>> >> > values stored in an array, I abandoned use of the "-ne" one-liner
>> >> > flag, using "-e"  and "for lines()" instead. I also used grep instead
>> >> > of smart-matching:
>> >> >
>> >> > perl6 -e 'my @i; for lines() {if .grep(/^WARN/) -> ($s)
>> >> > {@i.push($s)};}; .say for @i.sort;'
>> >> >
>> >> > Note: the "-> ($s)" section where I store grepped matches comes from a
>> >> > Jonathan Worthington answer found here (thanks Jonathan!):
>> >> >
>> >> > stackoverflow.com/questions/58982745/raku-one-line-expression-to-capture-group-from-string
>> >> >
>> >> > I certainly would be interested to learn if there's a phaser solution
>> >> > to this problem (and I also have a sneaking suspicion that Supply
>> >> > might be useful  here... ).
>> >> >
>> >> 

Re: Raku -npe command line usage

2020-05-08 Thread Andy Bach
>> raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> join("\n") ==> say()' 
>> sample.log
> raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> reduce({$^a ~ "\n" ~ $^b}) 
> ==> say()' sample.log

So what does reduce() do differently than join() here? I was thinking weeding 
out duplicates but it seems not.


From: Fernando Santagata 
Sent: Friday, May 8, 2020 2:16 PM
To: yary 
Cc: William Michels ; WFB ; 
perl6-users 
Subject: Re: Raku -npe command line usage

On Fri, May 8, 2020 at 6:10 PM Fernando Santagata 
mailto:nando.santag...@gmail.com>> 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 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 yary
> perl6 -e 'lines() ==> grep /^WARN/ ==> sort() ==> join("\n") ==> say();'

that's neat too.

This is showed me that I didn't have a clear grasp of the feed operator ==>
vs the hyper-operator >>

Now I have learned/internalized that the feed operators pass along the
entire sequence (list?), whereas the hyper-operator passes items one at a
time. Hence "==> say" putting the results on one line, because "say" is
getting the entire list. And  ">>.sort" not sorting, because sort would be
called once per item with only that single item to sort.

Boring hard-to-read solution not using any of those

raku -e'.say for sort grep *.starts-with(q[WARN]),lines' sample.log

-y

On Fri, May 8, 2020 at 1:20 PM William Michels 
wrote:

> 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.
> > 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()' sample.log
> >
> > outputs a list on one line, not each line on its own. This one works,
> but it feels awkward:
> >
> > raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> reduce({$^a ~ "\n" ~
> $^b}) ==> say()' sample.log
> >
> > On Fri, May 8, 2020 at 5:49 PM yary  wrote:
> >>
> >> All good ideas so far, in the "more than one way to do it" spirit, can
> use "state" instead of "my", since state only initializes 1st time it's hit.
> >>
> >> raku -ne 'state @i;@i.push($_) if .starts-with(q[WARN]); END .say
> for @i.sort' sample.log
> >>
> >> Or adapting Brad's answer with the feed operator for fun
> >>
> >> raku -e 'for lines() ==> grep /^WARN/ ==> sort() {.say}' sample.log
> >>
> >> Now, I didn't want to use 'map' in there, because of a habit of only
> using 'map' when I want the return values. When looping for side-effects
> only, like saying each value in a list, I want to use 'for'. UnFORtunately
> though I cannot find anything as clean looking as
> >>
> >> raku -e 'lines() ==> grep /^WARN/ ==> sort() ==> map *.say'
> sample.log
> >>
> >> reading entirely L-to-R which does NOT use map... ideas?
> >>
> >> -y
> >>
> >>
> >> On Fri, May 8, 2020 at 10:10 AM William Michels via perl6-users <
> perl6-us...@perl.org> wrote:
> >> >
> >> > 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 $_ ~~ /^WARN/; END {
> @i.sort.say }"
> >> > > That does not work because @i does not exist in the if clause. I
> tried our @i as well with no luck.
> >> > >
> >> > > How can I store data that can be accessed in the END phaser? Or is
> there another way to archive it? TIMTOWTDI^^
> >> > >
> >> > > One hint I found was the variable $ and @ respectively. But those
> variables are created for each line new...
> >> > >
> >> > >
> >> > > I did not found a help or examples for -npe except raku -h. Is
> there more helpful stuff somewhere in doc.raku.org? If so I could'nt find
> it.
> >> > >
> >> > > Thanks,
> >> > > Wolfgang
> >> >
> >> > Hi Wolfgang,
> >> >
> >> > This is a first attempt at doing what you want: I'm sure it can be
> >> > shortened. Since one of your requirements is doing a sort on filtered
> >> > values stored in an array, I abandoned use of the "-ne" one-liner
> >> > flag, using "-e"  and "for lines()" instead. I also used grep instead
> >> > of smart-matching:
> >> >
> >> > perl6 -e 'my @i; for lines() {if .grep(/^WARN/) -> ($s)
> >> > {@i.push($s)};}; .say for @i.sort;'
> >> >
> >> > Note: the "-> ($s)" section where I store grepped matches comes from a
> >> > Jonathan Worthington answer found here (thanks Jonathan!):
> >> >
> >> >
> stackoverflow.com/questions/58982745/raku-one-line-expression-to-capture-group-from-string
> >> >
> >> > I certainly would be interested to learn if there's a phaser solution
> >> > to this problem (and I also have a sneaking suspicion that Supply
> >> > might be useful  here... ).
> >> >
> >> > HTH, Bill.
> >
> >
> >
> > --
> > 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.
> 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()' sample.log
>
> outputs a list on one line, not each line on its own. This one works, but it 
> feels awkward:
>
> raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> reduce({$^a ~ "\n" ~ $^b}) 
> ==> say()' sample.log
>
> On Fri, May 8, 2020 at 5:49 PM yary  wrote:
>>
>> All good ideas so far, in the "more than one way to do it" spirit, can use 
>> "state" instead of "my", since state only initializes 1st time it's hit.
>>
>> raku -ne 'state @i;@i.push($_) if .starts-with(q[WARN]); END .say for 
>> @i.sort' sample.log
>>
>> Or adapting Brad's answer with the feed operator for fun
>>
>> raku -e 'for lines() ==> grep /^WARN/ ==> sort() {.say}' sample.log
>>
>> Now, I didn't want to use 'map' in there, because of a habit of only using 
>> 'map' when I want the return values. When looping for side-effects only, 
>> like saying each value in a list, I want to use 'for'. UnFORtunately though 
>> I cannot find anything as clean looking as
>>
>> raku -e 'lines() ==> grep /^WARN/ ==> sort() ==> map *.say' sample.log
>>
>> reading entirely L-to-R which does NOT use map... ideas?
>>
>> -y
>>
>>
>> On Fri, May 8, 2020 at 10:10 AM William Michels via perl6-users 
>>  wrote:
>> >
>> > 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 $_ ~~ /^WARN/; END { 
>> > > @i.sort.say }"
>> > > That does not work because @i does not exist in the if clause. I tried 
>> > > our @i as well with no luck.
>> > >
>> > > How can I store data that can be accessed in the END phaser? Or is there 
>> > > another way to archive it? TIMTOWTDI^^
>> > >
>> > > One hint I found was the variable $ and @ respectively. But those 
>> > > variables are created for each line new...
>> > >
>> > >
>> > > I did not found a help or examples for -npe except raku -h. Is there 
>> > > more helpful stuff somewhere in doc.raku.org? If so I could'nt find it.
>> > >
>> > > Thanks,
>> > > Wolfgang
>> >
>> > Hi Wolfgang,
>> >
>> > This is a first attempt at doing what you want: I'm sure it can be
>> > shortened. Since one of your requirements is doing a sort on filtered
>> > values stored in an array, I abandoned use of the "-ne" one-liner
>> > flag, using "-e"  and "for lines()" instead. I also used grep instead
>> > of smart-matching:
>> >
>> > perl6 -e 'my @i; for lines() {if .grep(/^WARN/) -> ($s)
>> > {@i.push($s)};}; .say for @i.sort;'
>> >
>> > Note: the "-> ($s)" section where I store grepped matches comes from a
>> > Jonathan Worthington answer found here (thanks Jonathan!):
>> >
>> > stackoverflow.com/questions/58982745/raku-one-line-expression-to-capture-group-from-string
>> >
>> > I certainly would be interested to learn if there's a phaser solution
>> > to this problem (and I also have a sneaking suspicion that Supply
>> > might be useful  here... ).
>> >
>> > HTH, Bill.
>
>
>
> --
> Fernando Santagata


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 .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 -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/;
>>
>> It's so nice how Raku essentially compiles the body of these file loops
>> into a little subroutine so that the "my" declaration only occurs once,
>> unlike how Perl 5 just textually wraps the loop with "while (<>) {" and "}"
>> which makes the declaration occur on every iteration.
>>
>> I originally figured this out when I idly worked up a classic
>> word-frequency-count one-liner:
>>
>> raku -ne '++(my %freq){$_} for m:g/\w+/; END .say for
>> %freq.antipairs.sort.reverse' file ...
>>
>>


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 -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/;
>
> It's so nice how Raku essentially compiles the body of these file loops
> into a little subroutine so that the "my" declaration only occurs once,
> unlike how Perl 5 just textually wraps the loop with "while (<>) {" and "}"
> which makes the declaration occur on every iteration.
>
> I originally figured this out when I idly worked up a classic
> word-frequency-count one-liner:
>
> raku -ne '++(my %freq){$_} for m:g/\w+/; END .say for
> %freq.antipairs.sort.reverse' file ...
>
>


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/;

It's so nice how Raku essentially compiles the body of these file loops
into a little subroutine so that the "my" declaration only occurs once,
unlike how Perl 5 just textually wraps the loop with "while (<>) {" and "}"
which makes the declaration occur on every iteration.

I originally figured this out when I idly worked up a classic
word-frequency-count one-liner:

raku -ne '++(my %freq){$_} for m:g/\w+/; END .say for
%freq.antipairs.sort.reverse' file ...


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 the
hyper-operator–

raku -e'(lines() ==> grep(/^WARN/) ==> sort)».say' sample.log

-y


On Fri, May 8, 2020 at 12:10 PM Fernando Santagata <
nando.santag...@gmail.com> wrote:

> 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()' sample.log
>
> outputs a list on one line, not each line on its own. This one works, but
> it feels awkward:
>
> raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> reduce({$^a ~ "\n" ~
> $^b}) ==> say()' sample.log
>
> On Fri, May 8, 2020 at 5:49 PM yary  wrote:
>
>> All good ideas so far, in the "more than one way to do it" spirit, can
>> use "state" instead of "my", since state only initializes 1st time it's hit.
>>
>> raku -ne 'state @i;@i.push($_) if .starts-with(q[WARN]); END .say
>> for @i.sort' sample.log
>>
>> Or adapting Brad's answer with the feed operator for fun
>>
>> raku -e 'for lines() ==> grep /^WARN/ ==> sort() {.say}' sample.log
>>
>> Now, I didn't want to use 'map' in there, because of a habit of only
>> using 'map' when I want the return values. When looping for side-effects
>> only, like saying each value in a list, I want to use 'for'. UnFORtunately
>> though I cannot find anything as clean looking as
>>
>> raku -e 'lines() ==> grep /^WARN/ ==> sort() ==> map *.say' sample.log
>>
>> reading entirely L-to-R which does NOT use map... ideas?
>>
>> -y
>>
>>
>> On Fri, May 8, 2020 at 10:10 AM William Michels via perl6-users <
>> perl6-us...@perl.org> wrote:
>> >
>> > 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 $_ ~~ /^WARN/; END {
>> @i.sort.say }"
>> > > That does not work because @i does not exist in the if clause. I
>> tried our @i as well with no luck.
>> > >
>> > > How can I store data that can be accessed in the END phaser? Or is
>> there another way to archive it? TIMTOWTDI^^
>> > >
>> > > One hint I found was the variable $ and @ respectively. But those
>> variables are created for each line new...
>> > >
>> > >
>> > > I did not found a help or examples for -npe except raku -h. Is there
>> more helpful stuff somewhere in doc.raku.org? If so I could'nt find it.
>> > >
>> > > Thanks,
>> > > Wolfgang
>> >
>> > Hi Wolfgang,
>> >
>> > This is a first attempt at doing what you want: I'm sure it can be
>> > shortened. Since one of your requirements is doing a sort on filtered
>> > values stored in an array, I abandoned use of the "-ne" one-liner
>> > flag, using "-e"  and "for lines()" instead. I also used grep instead
>> > of smart-matching:
>> >
>> > perl6 -e 'my @i; for lines() {if .grep(/^WARN/) -> ($s)
>> > {@i.push($s)};}; .say for @i.sort;'
>> >
>> > Note: the "-> ($s)" section where I store grepped matches comes from a
>> > Jonathan Worthington answer found here (thanks Jonathan!):
>> >
>> >
>> stackoverflow.com/questions/58982745/raku-one-line-expression-to-capture-group-from-string
>> >
>> > I certainly would be interested to learn if there's a phaser solution
>> > to this problem (and I also have a sneaking suspicion that Supply
>> > might be useful  here... ).
>> >
>> > HTH, Bill.
>>
>
>
> --
> Fernando Santagata
>


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()' sample.log

outputs a list on one line, not each line on its own. This one works, but
it feels awkward:

raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> reduce({$^a ~ "\n" ~ $^b})
==> say()' sample.log

On Fri, May 8, 2020 at 5:49 PM yary  wrote:

> All good ideas so far, in the "more than one way to do it" spirit, can use
> "state" instead of "my", since state only initializes 1st time it's hit.
>
> raku -ne 'state @i;@i.push($_) if .starts-with(q[WARN]); END .say for
> @i.sort' sample.log
>
> Or adapting Brad's answer with the feed operator for fun
>
> raku -e 'for lines() ==> grep /^WARN/ ==> sort() {.say}' sample.log
>
> Now, I didn't want to use 'map' in there, because of a habit of only using
> 'map' when I want the return values. When looping for side-effects only,
> like saying each value in a list, I want to use 'for'. UnFORtunately though
> I cannot find anything as clean looking as
>
> raku -e 'lines() ==> grep /^WARN/ ==> sort() ==> map *.say' sample.log
>
> reading entirely L-to-R which does NOT use map... ideas?
>
> -y
>
>
> On Fri, May 8, 2020 at 10:10 AM William Michels via perl6-users <
> perl6-us...@perl.org> wrote:
> >
> > 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 $_ ~~ /^WARN/; END {
> @i.sort.say }"
> > > That does not work because @i does not exist in the if clause. I tried
> our @i as well with no luck.
> > >
> > > How can I store data that can be accessed in the END phaser? Or is
> there another way to archive it? TIMTOWTDI^^
> > >
> > > One hint I found was the variable $ and @ respectively. But those
> variables are created for each line new...
> > >
> > >
> > > I did not found a help or examples for -npe except raku -h. Is there
> more helpful stuff somewhere in doc.raku.org? If so I could'nt find it.
> > >
> > > Thanks,
> > > Wolfgang
> >
> > Hi Wolfgang,
> >
> > This is a first attempt at doing what you want: I'm sure it can be
> > shortened. Since one of your requirements is doing a sort on filtered
> > values stored in an array, I abandoned use of the "-ne" one-liner
> > flag, using "-e"  and "for lines()" instead. I also used grep instead
> > of smart-matching:
> >
> > perl6 -e 'my @i; for lines() {if .grep(/^WARN/) -> ($s)
> > {@i.push($s)};}; .say for @i.sort;'
> >
> > Note: the "-> ($s)" section where I store grepped matches comes from a
> > Jonathan Worthington answer found here (thanks Jonathan!):
> >
> >
> stackoverflow.com/questions/58982745/raku-one-line-expression-to-capture-group-from-string
> >
> > I certainly would be interested to learn if there's a phaser solution
> > to this problem (and I also have a sneaking suspicion that Supply
> > might be useful  here... ).
> >
> > HTH, Bill.
>


-- 
Fernando Santagata


Re: Raku -npe command line usage

2020-05-08 Thread yary
All good ideas so far, in the "more than one way to do it" spirit, can use
"state" instead of "my", since state only initializes 1st time it's hit.

raku -ne 'state @i;@i.push($_) if .starts-with(q[WARN]); END .say for
@i.sort' sample.log

Or adapting Brad's answer with the feed operator for fun

raku -e 'for lines() ==> grep /^WARN/ ==> sort() {.say}' sample.log

Now, I didn't want to use 'map' in there, because of a habit of only using
'map' when I want the return values. When looping for side-effects only,
like saying each value in a list, I want to use 'for'. UnFORtunately though
I cannot find anything as clean looking as

raku -e 'lines() ==> grep /^WARN/ ==> sort() ==> map *.say' sample.log

reading entirely L-to-R which does NOT use map... ideas?

-y


On Fri, May 8, 2020 at 10:10 AM William Michels via perl6-users <
perl6-us...@perl.org> wrote:
>
> 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 $_ ~~ /^WARN/; END {
@i.sort.say }"
> > That does not work because @i does not exist in the if clause. I tried
our @i as well with no luck.
> >
> > How can I store data that can be accessed in the END phaser? Or is
there another way to archive it? TIMTOWTDI^^
> >
> > One hint I found was the variable $ and @ respectively. But those
variables are created for each line new...
> >
> >
> > I did not found a help or examples for -npe except raku -h. Is there
more helpful stuff somewhere in doc.raku.org? If so I could'nt find it.
> >
> > Thanks,
> > Wolfgang
>
> Hi Wolfgang,
>
> This is a first attempt at doing what you want: I'm sure it can be
> shortened. Since one of your requirements is doing a sort on filtered
> values stored in an array, I abandoned use of the "-ne" one-liner
> flag, using "-e"  and "for lines()" instead. I also used grep instead
> of smart-matching:
>
> perl6 -e 'my @i; for lines() {if .grep(/^WARN/) -> ($s)
> {@i.push($s)};}; .say for @i.sort;'
>
> Note: the "-> ($s)" section where I store grepped matches comes from a
> Jonathan Worthington answer found here (thanks Jonathan!):
>
>
stackoverflow.com/questions/58982745/raku-one-line-expression-to-capture-group-from-string
>
> I certainly would be interested to learn if there's a phaser solution
> to this problem (and I also have a sneaking suspicion that Supply
> might be useful  here... ).
>
> HTH, Bill.


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 $_ ~~ /^WARN/; END { @i.sort.say }"
> That does not work because @i does not exist in the if clause. I tried our @i 
> as well with no luck.
>
> How can I store data that can be accessed in the END phaser? Or is there 
> another way to archive it? TIMTOWTDI^^
>
> One hint I found was the variable $ and @ respectively. But those variables 
> are created for each line new...
>
>
> I did not found a help or examples for -npe except raku -h. Is there more 
> helpful stuff somewhere in doc.raku.org? If so I could'nt find it.
>
> Thanks,
> Wolfgang

Hi Wolfgang,

This is a first attempt at doing what you want: I'm sure it can be
shortened. Since one of your requirements is doing a sort on filtered
values stored in an array, I abandoned use of the "-ne" one-liner
flag, using "-e"  and "for lines()" instead. I also used grep instead
of smart-matching:

perl6 -e 'my @i; for lines() {if .grep(/^WARN/) -> ($s)
{@i.push($s)};}; .say for @i.sort;'

Note: the "-> ($s)" section where I store grepped matches comes from a
Jonathan Worthington answer found here (thanks Jonathan!):

stackoverflow.com/questions/58982745/raku-one-line-expression-to-capture-group-from-string

I certainly would be interested to learn if there's a phaser solution
to this problem (and I also have a sneaking suspicion that Supply
might be useful  here... ).

HTH, Bill.


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 would
automatically happen.

@i.push($_) if /^WARN/;

You probably also want the lines to be written each to to their own lines.
So you probably want one of the following.

@i.sort.map( *.say )
.say for @i.sort

Again you don't need to use a block with 「END」 either.

So together that would be:

raku -ne 'BEGIN my @i; @i.push($_) if /^WARN/; END .say for @i.sort'

---

That said, I wouldn't use -n in this case.

raku -e 'lines.grep( /^WARN/ ).sort.map( *.say )'

Currently regexes are a bit slow. You can use 「.starts-with」 instead to
make it faster.

raku -e 'lines.grep( *.starts-with(q[WARN]) ).sort.map( *.say )'

(Note that 「 'abc' 」 is short for 「 q'abc' 」 which can also be written as 「
q[abc] 」.
The latter is useful on the command line so that it doesn't interfere with
the command processor quoting rules.)

On Fri, May 8, 2020 at 7: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 $_ ~~ /^WARN/; END { @i.sort.say
> }"
> That does not work because @i does not exist in the if clause. I tried our
> @i as well with no luck.
>
> How can I store data that can be accessed in the END phaser? Or is there
> another way to archive it? TIMTOWTDI^^
>
> One hint I found was the variable $ and @ respectively. But those
> variables are created for each line new...
>
>
> I did not found a help or examples for -npe except raku -h. Is there more
> helpful stuff somewhere in doc.raku.org? If so I could'nt find it.
>
> Thanks,
> Wolfgang
>