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

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

Thread Previous | Thread Next
Darren Duncan
March 27, 2021 04:10
Re: Let's talk about trim() so more
Message ID:
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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About