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

More questions on the "-pe" one-liner flag: in conjunction with s///and tr///

Thread Next
From:
William Michels via perl6-users
Date:
May 6, 2020 21:11
Subject:
More questions on the "-pe" one-liner flag: in conjunction with s///and tr///
Message ID:
CAA99HCxFzX7H_gX3i7uXNgnhp-+XH+OR0nnk_-rSt39V5DQBGA@mail.gmail.com
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 Next


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