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

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

Thread Previous | Thread Next
Sam Kington
November 19, 2020 03:26
Re: Looking for someone to adopt adding trim() to core
Message ID:
I think I now understand what the point of Perl 7 is.

In Perl 7+, you say use feature “trim” (or specify a version of perl that includes that feature) and you get a native trim feature.

In earlier Perls, if you have control of your environment, you either use a version of Scalar::Util (or whatever) that implements the exact same trim() function, or you roll your own by saying s/^\s+//g; s/\s+$//g in a module of your choosing and export that into the caller’s namespace.

If you’re writing code for the CPAN where you don’t get to say what modules people have installed, you say s/^\s+//g; s/\s+$//g; unless someone has written String::Trim::Tiny and you think that’s a reasonable dependency, and you can use that in your code.

I was on the fence about this, but I’m now happy to see trim() in the next version of Perl, as an example of how we can add stuff to the core and learn from that and, next time, add more interesting things.

On 18 Nov 2020, at 23:01, Christian Walde <> wrote:

The point is to minimize the work a non-cpan developer has to do to have access to the function.

Precisely because it's implementation is so small, in the range of the code needed for say, it must also be able to be used with minimum effort.

The suggestions you have, of tracking dependencies beyond Perl version, would increase the work-to-use needed to a point where the entire undertaking is wholly pointless.

Also, to be frank, nothing you said actually adresses the email you replied to. At all.

say is also "just a function" and is extremely similar in many ways. To treat trim any different from say requires extremely strong arguments to explain how it is different from say.

On Wed, 18 Nov 2020 23:31:41 +0100, Yuki Kimoto <> wrote:

I think trim is just a function.

The function means that it takes arguments and returns return value.

I think the benefits of adding trim as a Perl grammar are small.

I think it's a best idea to add trim to Scalar::Util.

use Scalar::Util 'trim';

trim $string;

The reason is that there are a few changes and the benefits are great.

I think The next best idea is to add a new namespace.

use Scalar 'trim';

trim $string;

This adds a new namespace, or module, so the size of the changes will be a bit larger.

2020年11月19日(木) 5:20 Christian Walde < <>>:
One more note:

say is EXTREMELY similar to trim, and as far as i can tell was VERY well received and caused no significant issues. Right?

With regards,
Christian Walde


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