develooper 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
From:
Gianni Ceccarelli
Date:
May 6, 2020 21:30
Subject:
Re: More questions on the "-pe" one-liner flag: in conjunction withs/// and tr///
Message ID:
20200506222956.12a2345e@thenautilus.net
On 2020-05-06 William Michels via perl6-users <perl6-users@perl.org>
wrote:
> 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?

Because they're not function calls, but *mutating* operators. As the
documentation says
https://docs.raku.org/language/operators#s///_in-place_substitution
``s///`` is an "in-place substitution":

    s/// operates on the $_ topical variable, changing it in place

and ``tr///``
https://docs.raku.org/language/operators#tr///_in-place_transliteration
says the same:

    tr/// operates on the $_ topical variable and changes it in place

And as usual, ``-p`` prints the value of ``$_`` at the end of each
loop, so you get the modified value.

-- 
	Dakkar - <Mobilis in mobile>
	GPG public key fingerprint = A071 E618 DD2C 5901 9574
	                             6FE2 40EA 9883 7519 3F88
	                    key id = 0x75193F88

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