develooper Front page | perl.perl5.porters | Postings from July 2020

Re: Request review for adding a text trim() function to core

Thread Previous
From:
Dan Book
Date:
July 21, 2020 19:56
Subject:
Re: Request review for adding a text trim() function to core
Message ID:
CABMkAVWHyqRUeYR=5PRrA1d8vZAZ9muzYTEUtBpqcgF_cWy4AQ@mail.gmail.com
On Tue, Jul 21, 2020 at 3:47 PM Alexander Hartmaier <
alex.hartmaier@gmail.com> wrote:

> On Tue, Jul 21, 2020 at 8:35 PM Eric Brine <ikegami@adaelis.com> wrote:
>
>> Having a function to trim both ends but not one to trim trailing
>> whitespace is really weird to me. Virtually every program I write needs the
>> latter (though I usually settle for chomp).
>>
>> On Tue, Jul 21, 2020 at 1:59 PM Scott Baker <scott@perturb.org> wrote:
>>
>>> It's been a personal pet peeve of mine that Perl has never had a
>>> *trim()* function in core. After discussion
>>> <https://github.com/Perl/perl5/issues/17952> with Grinnz, Leonerd, and
>>> others we decided to move forward with seeing what it would take to add it
>>> to core. I wrote documentation and tests, and LeoNerd wrote the actual
>>> implementation. Now I'm here soliciting feedback on this feature before I
>>> submit a formal PR.
>>>
>>> You can checkout my branch here:
>>> https://github.com/scottchiefbaker/perl5/tree/trim
>>>
>>> Once it's built the easier way to test it is: ./perl -Ilib -E 'say
>>> CORE::trim("   Hello world!    ");'
>>>
>>> You will get an experimental warning, but the function should work and
>>> remove the whitespace.
>>>
>>> - Scottchiefbaker
>>>
>>
> I've added some comments on Github but overall I'd love to see such a
> function!
> Control over what characters should be trimmed would be awesome and
> default to what it currently does.
> That way you could also use it to trim brackets for example.
>

Control over what is trimmed was discussed in the ticket, summarized here:
https://github.com/Perl/perl5/issues/17952#issuecomment-658462652

Ultimately we decided at least for now it is too much complication without
an obvious and simple form the interface should take - and it is simple to
do this with custom regexes should you need something slightly different.

-Dan

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