Re: steps of a path

2022-09-05 Thread Marc Chantreux
Hi Ralph,

> The `.Str.say` can be just `.put`.

oh! got it. thanks :)

> If not, can you see why I'm surprised -- why `m:g{ "/" <-[/]>+ }`
> seems simpler to me than `m:ex{^ [:r "/" <-[/]>+]+? }`?

I just played again with your solution and got the beauty of it. why
made me realize I should take time between two post so I can have a
fresh mindset for all of them!

Actually: this is by far the simplest solution. Thanks.


-- 
Marc Chantreux
Pôle de Calcul et Services Avancés à la Recherche (CESAR)
http://annuaire.unistra.fr/p/20200


Re: steps of a path

2022-09-05 Thread Fernando Santagata
Hello,

you can get around the immutability problem:

raku -e '"/var/log/messages".IO.map: -> $_ is copy {repeat {.put} while !
($_ .= parent ~~ "/") }'


On Mon, Sep 5, 2022 at 8:55 AM Marc Chantreux  wrote:

> hello William,
>
> On Sat, Sep 03, 2022 at 04:27:04PM -0700, William Michels wrote:
> > Hi Marc, There's also this conversation from March 2021 on the mailing
> list:
> > https://www.nntp.perl.org/group/perl.perl6.users/2021/03/msg9857.html
> > [Matthew's answer looks very interesting].
>
> Interesting as it can provide a relative short solution with no advanced
> concept. I tried this line but got an immutability problem. I tried
> multiple work around with no success for the moment.
>
> <<. raku -e 'lines.IO.map: {repeat {.put} while not .=parent ~~ "/" }'
> /var/log/messages
>
> thank you
>
> --
> Marc Chantreux
> Pôle de Calcul et Services Avancés à la Recherche (CESAR)
> http://annuaire.unistra.fr/p/20200
>


-- 
Fernando Santagata


Re: steps of a path

2022-09-05 Thread Bruce Gray
> On Sep 5, 2022, at 1:54 AM, Marc Chantreux  wrote:
--snip of Bill's pointer to Mathew's email--
> I tried this line but got an immutability problem. I tried
> multiple work around with no success for the moment.
> <<. raku -e 'lines.IO.map: {repeat {.put} while not .=parent ~~ "/" }'
> /var/log/messages
--snip--

> On Sep 5, 2022, at 2:40 AM, Fernando Santagata  
> wrote:
> you can get around the immutability problem:
> raku -e '"/var/log/messages".IO.map: -> $_ is copy {repeat {.put} while ! ($_ 
> .= parent ~~ "/") }'

--snip--

The use of `.parent` inspired me to think of this shorter solution, via the 
Sequence Operator:
$ raku -e '.put for "/var/log/messages".IO, *.parent …^ "/";'
/var/log/messages
/var/log
/var

https://docs.raku.org/language/operators#infix_...

-- 
Hope this helps,
Bruce Gray (Util of PerlMonks)



Re: steps of a path

2022-09-05 Thread Marc Chantreux
I love this one. I used uniq and run so the whole script can be run from
raku (except the xargs ls avoid the ARG_MAX error)

<<. raku -e 'run < ls -lUd >, unique map {(.IO, *.parent …^ "/")>>.Str.Slip}, 
lines'
/var/log/messages
/var/log/auth.log

regards

-- 
Marc Chantreux
Pôle de Calcul et Services Avancés à la Recherche (CESAR)
http://annuaire.unistra.fr/p/20200