develooper Front page | perl.perl5.porters | Postings from March 2021

Re: Let's talk about trim() so more

Thread Previous | Thread Next
From:
Salvador Fandiño
Date:
March 29, 2021 10:52
Subject:
Re: Let's talk about trim() so more
Message ID:
8a19f81d-ded5-4c9f-26f9-56047acd2096@gmail.com
On 29/3/21 12:36, Felipe Gasper wrote:
> 
> 
>> On Mar 29, 2021, at 6:30 AM, Salvador Fandiño <sfandino@gmail.com> wrote:
>>
>> On 27/3/21 8:59, B. Estrade wrote:
>>> On 3/26/21 11:50 PM, Darren Duncan wrote:
>>
>>> Can we just add "im" as modifiers to tr/// ? It comes with the handy mnemonic, "tr///im".
>>> my $new_str = tr/$str/\s/im;
>>> Everybody wins. tr/// (and versus regexes) is no less confusing to newbies and seasoned Perlers, alike.
>>
>> You may be joking, but IMO adding a modifier to tr/// and s/// (say "b"), so that they match just at the beginning and at the end of lines would be a nice addition to the language:
>>
>>   $foo =~ s/\s+//bg;
>>   $foo =~ s/\s+//bmg;
> 
> Isn’t that what ^ already does with the /m modifier?

I don't think so...

     my $foo = " hello \n world ! ";
     say $foo =~ s/^\s+/^/mgr;
     say $foo =~ s/(?:^\s+|\s+$)/B/mgr; # equivalent to s/\s+//bmgr

     # output:
     ^hello
     ^world !
     BhelloB
     Bworld !B


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