hello people,

I have this steps() function implemented this way in shell:

steps() sed -r ':b p; s,/[^/]+$,,; t b'
# demo:
<<. steps | xargs ls -lUd
/var/log/messages

which shows

-rw-r-----  1 root adm  464304 Sep  3 19:03 /var/log/messages
drwxr-xr-x 22 root root   4096 Sep  3 00:00 /var/log
drwxr-xr-x 14 root root   4096 Jun 19  2021 /var

for those who don't know sed that much, the perl equivalent is:

        steps() perl -lpe 'do {print} while s,/[^/]+$,,'

I thought the raku one could be shorter but for now I'm stuck
with a very long solution.

my \path = [ "/var/log/messages" .split: "/" ];
.say for (^path).map( { path[0..$_].join: "/" } )[1..*];

I'm pretty sure I saw a very concise and elegant way to transform
( A B C ) to ((A) (A B) (A B C)) in the past but I'm enable to figure
out how. Any help on that ?

thanks by advance.

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

Reply via email to