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

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

Thread Previous | Thread Next
Vlado Keselj
November 26, 2020 12:14
Re: Looking for someone to adopt adding trim() to core
Message ID:

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.

My $.02 :)


On Thu, 26 Nov 2020, Tony Cook wrote:

> On Wed, Nov 11, 2020 at 04:01:47PM +0100, demerphq wrote:
> > Why does it need to be added to the language as a new keyword? You
> > could add it via universal.c to the SCALAR namespace (for example) and
> > have it accessible without any feature horribleness. I believe we have
> > already approved that such namespaces are acceptable. And additions to
> > them do not need any feature bodge and are trivially made backwards
> > compatible.
> > 
> > print SCALAR::trim($str);
> > 
> > I vote "no" to this as a feature. But I am fine with it being in core
> > via universal.c and the right namespace.
> The same arguments could be made for fc(), say() and evalbytes().
> I'm a bit on the fence with trim() in particular, but tend slightly
> towards including it.  I think it would see more usage than chop() for
> example.
> I don't recall any discussion about a SCALAR namespace or anything
> similar (though there was mauve IIRC).
> Ideally we'd have strings-as-objects, and we could add trim() as a
> method, which I think would be uncontroversial, but we don't have
> those, and I don't see a simple way to change it ("Foo"->trim already
> has a meaning).
> Tony

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About