Front page | perl.perl6.users |
Postings from May 2020
Re: More questions on the "-pe" one-liner flag: in conjunction withs/// and tr///
Thread Previous
|
Thread Next
From:
William Michels via perl6-users
Date:
May 6, 2020 23:58
Subject:
Re: More questions on the "-pe" one-liner flag: in conjunction withs/// and tr///
Message ID:
CAA99HCwdyKesA3R2-w2JyXD39_etF8YJ2DZ_Va9F7wvQfQNscw@mail.gmail.com
Thank you Laurent!
Are there any other "operators that modify their operands" in
Raku/Perl6 that don't require an initializing "." (dot)?
I checked the "subst" command and it requires an initial ".=" when
used with the "-pe" one-liner flag:
mbook:~ homedir$ perl6 -pe '.=subst(/love|like/, "admire"); ' demo1.txt
this is a test,
I admire Unix,
I admire Linux too,
mbook:~ homedir$
Thanks in advance, Bill.
On Wed, May 6, 2020 at 3:18 PM Laurent Rosenfeld
<laurent.rosenfeld@googlemail.com> wrote:
>
> The s/// substitution operator is not a method (and tr/// also not). They both modify their operands, so there is no need anyway for a '.=' syntax, since they do already what the '.=' syntax is aimed at.
>
> Cheers,
> Laurent.
>
> Garanti sans virus. www.avast.com
>
> Le mer. 6 mai 2020 à 23:11, William Michels <wjm1@caa.columbia.edu> a écrit :
>>
>> Hello,
>>
>> Can anyone answer why--in a one-liner using the "-pe" flag--the s///
>> and tr/// functions do not require a "." (dot) preceding the function
>> call? Clearly adding a "." (dot) before either one results in an error
>> (code below). Also, adding a ".=" (dot-equals) sign before the either
>> the s/// or the tr/// function results in an error (code below).
>> Additionally, I would like to know if this is a related-or-different
>> issue compared to the question I posted earlier this week.
>>
>> Any explanation or assistance appreciated,
>>
>> Thank you, Bill.
>>
>> mbook:~ homedir$ cat demo1.txt
>> this is a test,
>> I love Unix,
>> I like Linux too,
>> mbook:~ homedir$
>>
>> mbook:~ homedir$ perl6 -pe 's/love|like/admire/; ' demo1.txt
>> this is a test,
>> I admire Unix,
>> I admire Linux too,
>> mbook:~ homedir$ perl6 -pe '.s/love|like/admire/; ' demo1.txt
>> ===SORRY!=== Error while compiling -e
>> Missing required term after infix
>> at -e:1
>> ------> .s/love|like/admire/;
>> expecting any of:
>> prefix
>> term
>> mbook:~ homedir$ perl6 -pe '.=s/love|like/admire/; ' demo1.txt
>> ===SORRY!=== Error while compiling -e
>> Missing required term after infix
>> at -e:1
>> ------> .=s/love|like/admire/;
>> expecting any of:
>> prefix
>> term
>> mbook:~ homedir$
>>
>> mbook:~ homedir$ perl6 -pe 'tr/aeiou/12345/;' demo1.txt
>> th3s 3s 1 t2st,
>> I l4v2 Un3x,
>> I l3k2 L3n5x t44,
>> mbook:~ homedir$ perl6 -pe '.tr/aeiou/12345/;' demo1.txt
>> ===SORRY!=== Error while compiling -e
>> Missing required term after infix
>> at -e:1
>> ------> .tr/aeiou/12345/;
>> expecting any of:
>> prefix
>> term
>> mbook:~ homedir$ perl6 -pe '.=tr/aeiou/12345/;' demo1.txt
>> ===SORRY!=== Error while compiling -e
>> Missing required term after infix
>> at -e:1
>> ------> .=tr/aeiou/12345/;
>> expecting any of:
>> prefix
>> term
>> mbook:~ homedir$
Thread Previous
|
Thread Next