develooper Front page | perl.perl6.users | Postings from July 2020

Re: delimiters with more than one character? ...

Thread Previous | Thread Next
From:
yary
Date:
July 17, 2020 13:26
Subject:
Re: delimiters with more than one character? ...
Message ID:
CAG2CFAZnpvO2FJ=cFmEHxPULR4G_kd4qeenWQPQsA6NMkYU+Kw@mail.gmail.com
FYI the original thread is viewable at
https://www.mail-archive.com/debian-user@lists.debian.org/msg758713.html
and the post has several reasonable answers there. Among the first is a
classic Perl one-liner and suggestions along the lines of "what you're
doing looks brittle, how about doing the whole thing in Perl" and "tell use
what you really want to accomplish and we'll find a better solution!"

Raku content for fun and practice

$ *echo ' 34 + 45 \| abc \| 1 2 3 \| c\|123abc '*
 34 + 45 \| abc \| 1 2 3 \| c\|123abc
$
*# Good, shell echo preserves \| combo*$ echo ' 34 + 45 \| abc \| 1 2 3 \|
c\|123abc ' | raku -pe 's:g/\\ \| / \n /'

 34 + 45

  abc

  1 2 3

  c

 123abc


-y

-y


On Thu, Jul 16, 2020 at 2:51 PM William Michels via perl6-users <
perl6-users@perl.org> wrote:

> ---------- Forwarded message ---------
> Date: Thu, Jul 16, 2020 at 11:42 AM
> Subject: Re: delimiters with more than one character?
> To: <debian-user@lists.debian.org>
>
> 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.
>
>
>
>
>
> On Thu, Jul 16, 2020 at 5:35 AM Tom Browder <tom.browder@gmail.com> wrote:
>
>> An opportunity for Raku golfers to show off Raku on the Debian users list.
>>
>> Best regards,
>>
>> -Tom
>>
>> ---------- Forwarded message ---------
>> From: Albretch Mueller <lbrtchx@gmail.com>
>> Date: Tue, Jul 14, 2020 at 07:52
>> Subject: delimiters with more than one character? ...
>> To: Debian Users ML <debian-user@lists.debian.org>
>>
>>
>>  I have a string delimited by two characters: "\|"
>>
>>  _S=" 34 + 45 \| abc \| 1 2 3 \| c\|123abc "
>>
>>  which then I need to turn into a array looking like:
>>
>>   _S_AR=(
>> " 34 + 45 "
>> " abc "
>> " 1 2 3 "
>> " c"
>> "123abc "
>> )
>>
>>   I can't make awk or tr work in the way I need and all examples I
>> have found use only one character.
>>
>>   Is it possible to do such things in bash?
>>
>>   lbrtchx
>>
>>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About