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

Re: Looking for someone to adopt adding trim() to core

Thread Previous | Thread Next
From:
Vlado Keselj
Date:
November 26, 2020 12:53
Subject:
Re: Looking for someone to adopt adding trim() to core
Message ID:
alpine.LFD.2.20.2011260847100.6825@tr

1050 distributions and 1659 cases!  Wow, that is a strong support for 
"trim".

It is interesting that some of those cases use /g option, which trims all 
lines.  This could be a candidate for the second argument of "trim".

I would guess that not even all alternatives are counted, like:
s/^\s*(.*)\s*$/$1/


On Thu, 26 Nov 2020, Christian Walde wrote:

> On Thu, 26 Nov 2020 12:43:01 +0100, Vlado Keselj <vlado@dnlp.ca> wrote:
> 
> >Hi,
> >
> >I am new to the list so I am not sure if this counts for much, but I would
> >be in support of making "trim" a keyword.
> >
> >Perl is a string-oriented language and it should be simple and transparent
> >to use functions like "trim", which made keywords already in other
> >languages, like PHP.  Yes, we can use regexes but they do look hairy for
> >such a simple use.  This would be an important benefit to the beginners.
> >If 'chomp' is there, why 'trim' would not be.  One possible dowside may be
> >backcompatibility.  It would be worth checking how much and how 'trim' has
> >already been used in CPAN.
> 
> Thanks for the support. :)
> 
> As for the numbers checking, i already did that here:
> 
> >And looking at CPAN:
> >https://grep.metacpan.org/search?q=%5C%5E%5C%5Cs%5C%2B%5B%5E%5C0%5D%2B%5C%5Cs%5C%2B%5C%24%7C%5C%5Cs%5C%2B%5C%24%5B%5E%5C0%5D%2B%5C%5E%5C%5Cs%5C%2B&qd=&qft=
> >1050 distributions and 1659 files implement some kind of regex-based
> >whitespace stripping, and while this function isn't aimed at CPAN, this
> >demonstrates a clear desire.
> >For a (not at all equal, but related) comparison, searching for uses of say:
> >https://grep.metacpan.org/search?q=%5Cbsay%5B+%28%5D&qd=&qft=
> >results in 914 dists.
> 
> That said, backporting is not a big concern for this one, as trim is primarily
> aimed at non-CPAN developers for their own code, as trim is more likely to be
> used in end user code, not library code. :)
> 
> It would also be a small marketing win alongside of the other benefits of it
> being a proof-of-concept and learning aid for adding functionality to Perl.
> 

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