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

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

Thread Previous | Thread Next
From:
neilb
Date:
March 30, 2021 23:58
Subject:
RE: Let's talk about trim() so more
Message ID:
6c62bb49-8a05-46bb-bfe4-c5ef7d2313f1@Spark
> I don't understand all the hullaballoo about trim().And I don't get why it ever should be implemented in core.Removing something from the beginning and/or end from some something isa no-brainer in perl.

Trimming is something that is frequently wanted, but though you think it a no-brainer, people don’t always get it right. I found about 7500 distributions with an "inline trim". Here are some of the ones I found:

    s/(^\s+)|(\s+$)//;
    s/(^\s+)|\n//gm;
    s/(^\s+|\s+$)//g;
    s/(^\s+)|(\s+$)//g;
    s/(^\s+|\s+$)//os;
    s/(^\s+|\s+$)//gs;
    s/^\s*//; s/\s+$//;

Not all of those work.

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