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

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

Thread Previous
From:
Marcel Timmerman
Date:
July 16, 2020 13:58
Subject:
Re: delimiters with more than one character? ...
Message ID:
5d08e2e1-24f6-81c0-9093-4c99a784d85d@gmail.com
On 2020-07-16 15:17, Parrot Raiser wrote:
> Perhaps with a grammar?
>
> On 7/16/20, 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
>>

A single quoted string:
' 34 + 45 \| abc \| 1 2 3 \| c\|123abc '.split('\|').join(', ');
returns: 34 + 45 ,  abc ,  1 2 3 ,  c, 123abc

A double quoted string interprets '\' so;
" 34 + 45 \| abc \| 1 2 3 \| c\|123abc ".split('|').join(', ')
returns: 34 + 45 ,  abc ,  1 2 3 ,  c, 123abc

spaces are still left in. The join is used to show the strings in the 
array a bit better.

Regards,
Marcel

Thread Previous


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