[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: delimiters with more than one character?



<a href="" href="mailto:debian-user@lists.debian.org" target="_blank">debian-user@lists.debian.org?in-reply-to=<[🔎] CAFakBwhN7crFsov60mR9tF4VUS1Duv4CNQohBBDyX-AWOXW-Kw@mail.gmail.com" target="_blank">[🔎] CAFakBwhN7crFsov60mR9tF4VUS1Duv4CNQohBBDyX-AWOXW-Kw@mail.gmail.com>&amp;subject=Re:%20Re: delimiters with more than one character? ...">debian-user@lists.debian.org</a>

I've slowly been learning the Raku programming language (AKA Perl6), and while I'm far from being an expert, this is the first solution I came up with (raku one-or-two-liners, at the bash command prompt):

user@mbook:~$ raku -e ' my Str $s=" 34 + 45 \| abc \| 1 2 3 \| c\|123abc "; $s.put';
 34 + 45 | abc | 1 2 3 | c|123abc
user@mbook:~$ raku -e ' my Str $s=" 34 + 45 \| abc \| 1 2 3 \| c\|123abc "; $s.split("|").raku.put';
(" 34 + 45 ", " abc ", " 1 2 3 ", " c", "123abc ").Seq
user@mbook:~$ raku -e ' my Str $s=" 34 + 45 \| abc \| 1 2 3 \| c\|123abc "; .put for $s.split("|");'
 34 + 45
 abc
 1 2 3
 c
123abc
user@mbook:~$ raku -e ' my Str $s=" 34 + 45 \| abc \| 1 2 3 \| c\|123abc "; .raku.put for $s.split("|");'
" 34 + 45 "
" abc "
" 1 2 3 "
" c"
"123abc "
user@mbook:~$

Looking at the Str typed-variable $s I see that backslash escapes are removed automatically (the second command only has to split on the pipe character). So maybe this isn't a general solution, but it works for the example given.

https://raku.org/

HTH, Bill.

(Apologies if this message gets threaded improperly).




Reply to: