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

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

Thread Previous | Thread Next
From:
Darren Duncan
Date:
March 27, 2021 04:10
Subject:
Re: Let's talk about trim() so more
Message ID:
68a94503-684b-cad1-9ba6-54c53b59caf8@darrenduncan.net
On 2021-03-26 5:53 p.m., B. Estrade wrote:
> Just replying to the latest, not necessarily this post. But I think it is 
> reasonable to consider the precedent set by chomp(). In the GH thread, it seemed 
> there was some confusion that trim was going to provide just the trim'ing of 
> *leading* white space. I think this is a reasonable assumption that it was 
> completing the corollary of chomp.
> 
> I think it is reasonable "trim" does "chomp + trim leading white space" which is 
> a common idiom - perhaps vulgar, but an idiom nonetheless. The fact that trim 
> returns the value rather than affecting the value itself - an idiom we're used 
> to via passing data by reference - is *surprising*.

I believe it completely mis-characterizes "chomp" to treat "trim" as being 
"chomp + trim leading white space".

The chomp(), like chop(), is very narrowly focused on removing a trailing line 
break, and is not about removing trailing whitespace generally, which trim() is 
explicitly all about.

A most common use case of trim() is to clean up user input where they may have 
typed or pasted spaces before or after their main input in some form input field 
or such.

-- Darren Duncan

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