Request review for adding a text trim() function to core

--------------33515998C41DEF870249E088
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

It's been a personal pet peeve of mine that Perl has never had a
*trim()* function in core. After discussion
<https://github.com/Perl/perl5/issues/17952> with Grinnz, Leonerd, and
others we decided to move forward with seeing what it would take to add
it to core. I wrote documentation and tests, and LeoNerd wrote the
actual implementation. Now I'm here soliciting feedback on this feature
before I submit a formal PR.

You can checkout my branch here:
https://github.com/scottchiefbaker/perl5/tree/trim

Once it's built the easier way to test it is: ./perl -Ilib -E 'say
CORE::trim("   Hello world!    ");'

You will get an experimental warning, but the function should work and
remove the whitespace.

- Scottchiefbaker


--------------33515998C41DEF870249E088
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit

<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>It's been a personal pet peeve of mine that Perl has never had a
      <b>trim()</b> function in core. After <a moz-do-not-send="true"
        href="https://github.com/Perl/perl5/issues/17952">discussion</a>
      with Grinnz, Leonerd, and others we decided to move forward with
      seeing what it would take to add it to core. I wrote documentation
      and tests, and LeoNerd wrote the actual implementation. Now I'm
      here soliciting feedback on this feature before I submit a formal
      PR.</p>
    <p>You can checkout my branch here:
      <a class="moz-txt-link-freetext" href="https://github.com/scottchiefbaker/perl5/tree/trim">https://github.com/scottchiefbaker/perl5/tree/trim</a></p>
    <p>Once it's built the easier way to test it is: <tt>./perl -Ilib
        -E 'say CORE::trim("   Hello world!    ");'</tt></p>
    <p>You will get an experimental warning, but the function should
      work and remove the whitespace.<br>
    </p>
    <p>- Scottchiefbaker<tt><br>
      </tt></p>
  </body>
</html>

--------------33515998C41DEF870249E088--
0
scott
7/21/2020 5:59:38 PM
perl.perl5.porters 48174 articles. 1 followers. Follow

3 Replies
22 Views

Similar Articles

[PageSpeed] 10

--0000000000005f4bc705aaf7e239
Content-Type: text/plain; charset="UTF-8"

Having a function to trim both ends but not one to trim trailing whitespace
is really weird to me. Virtually every program I write needs the latter
(though I usually settle for chomp).

On Tue, Jul 21, 2020 at 1:59 PM Scott Baker <scott@perturb.org> wrote:

> It's been a personal pet peeve of mine that Perl has never had a *trim()*
> function in core. After discussion
> <https://github.com/Perl/perl5/issues/17952> with Grinnz, Leonerd, and
> others we decided to move forward with seeing what it would take to add it
> to core. I wrote documentation and tests, and LeoNerd wrote the actual
> implementation. Now I'm here soliciting feedback on this feature before I
> submit a formal PR.
>
> You can checkout my branch here:
> https://github.com/scottchiefbaker/perl5/tree/trim
>
> Once it's built the easier way to test it is: ./perl -Ilib -E 'say
> CORE::trim("   Hello world!    ");'
>
> You will get an experimental warning, but the function should work and
> remove the whitespace.
>
> - Scottchiefbaker
>

--0000000000005f4bc705aaf7e239
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Having a function to trim both ends but not one to trim tr=
ailing whitespace is really weird to me. Virtually every program I write ne=
eds the latter (though I usually settle for chomp).<br></div><br><div class=
=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Tue, Jul 21, 2020=
 at 1:59 PM Scott Baker &lt;<a href=3D"mailto:scott@perturb.org">scott@pert=
urb.org</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"=
margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-lef=
t:1ex">
 =20

   =20
 =20
  <div>
    <p>It&#39;s been a personal pet peeve of mine that Perl has never had a
      <b>trim()</b> function in core. After <a href=3D"https://github.com/P=
erl/perl5/issues/17952" target=3D"_blank">discussion</a>
      with Grinnz, Leonerd, and others we decided to move forward with
      seeing what it would take to add it to core. I wrote documentation
      and tests, and LeoNerd wrote the actual implementation. Now I&#39;m
      here soliciting feedback on this feature before I submit a formal
      PR.</p>
    <p>You can checkout my branch here:
      <a href=3D"https://github.com/scottchiefbaker/perl5/tree/trim" target=
=3D"_blank">https://github.com/scottchiefbaker/perl5/tree/trim</a></p>
    <p>Once it&#39;s built the easier way to test it is: <tt>./perl -Ilib
        -E &#39;say CORE::trim(&quot;=C2=A0=C2=A0 Hello world!=C2=A0=C2=A0=
=C2=A0 &quot;);&#39;</tt></p>
    <p>You will get an experimental warning, but the function should
      work and remove the whitespace.<br>
    </p>
    <p>- Scottchiefbaker<tt><br>
      </tt></p>
  </div>

</blockquote></div>

--0000000000005f4bc705aaf7e239--
0
ikegami
7/21/2020 6:35:03 PM
--000000000000cb5b0e05aaf8e463
Content-Type: text/plain; charset="UTF-8"

On Tue, Jul 21, 2020 at 8:35 PM Eric Brine <ikegami@adaelis.com> wrote:

> Having a function to trim both ends but not one to trim trailing
> whitespace is really weird to me. Virtually every program I write needs the
> latter (though I usually settle for chomp).
>
> On Tue, Jul 21, 2020 at 1:59 PM Scott Baker <scott@perturb.org> wrote:
>
>> It's been a personal pet peeve of mine that Perl has never had a *trim()*
>> function in core. After discussion
>> <https://github.com/Perl/perl5/issues/17952> with Grinnz, Leonerd, and
>> others we decided to move forward with seeing what it would take to add it
>> to core. I wrote documentation and tests, and LeoNerd wrote the actual
>> implementation. Now I'm here soliciting feedback on this feature before I
>> submit a formal PR.
>>
>> You can checkout my branch here:
>> https://github.com/scottchiefbaker/perl5/tree/trim
>>
>> Once it's built the easier way to test it is: ./perl -Ilib -E 'say
>> CORE::trim("   Hello world!    ");'
>>
>> You will get an experimental warning, but the function should work and
>> remove the whitespace.
>>
>> - Scottchiefbaker
>>
>
I've added some comments on Github but overall I'd love to see such a
function!
Control over what characters should be trimmed would be awesome and default
to what it currently does.
That way you could also use it to trim brackets for example.

--000000000000cb5b0e05aaf8e463
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail=
_attr">On Tue, Jul 21, 2020 at 8:35 PM Eric Brine &lt;<a href=3D"mailto:ike=
gami@adaelis.com">ikegami@adaelis.com</a>&gt; wrote:<br></div><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px soli=
d rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">Having a function to =
trim both ends but not one to trim trailing whitespace is really weird to m=
e. Virtually every program I write needs the latter (though I usually settl=
e for chomp).<br></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" clas=
s=3D"gmail_attr">On Tue, Jul 21, 2020 at 1:59 PM Scott Baker &lt;<a href=3D=
"mailto:scott@perturb.org" target=3D"_blank">scott@perturb.org</a>&gt; wrot=
e:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0=
..8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
 =20

   =20
 =20
  <div>
    <p>It&#39;s been a personal pet peeve of mine that Perl has never had a
      <b>trim()</b> function in core. After <a href=3D"https://github.com/P=
erl/perl5/issues/17952" target=3D"_blank">discussion</a>
      with Grinnz, Leonerd, and others we decided to move forward with
      seeing what it would take to add it to core. I wrote documentation
      and tests, and LeoNerd wrote the actual implementation. Now I&#39;m
      here soliciting feedback on this feature before I submit a formal
      PR.</p>
    <p>You can checkout my branch here:
      <a href=3D"https://github.com/scottchiefbaker/perl5/tree/trim" target=
=3D"_blank">https://github.com/scottchiefbaker/perl5/tree/trim</a></p>
    <p>Once it&#39;s built the easier way to test it is: <tt>./perl -Ilib
        -E &#39;say CORE::trim(&quot;=C2=A0=C2=A0 Hello world!=C2=A0=C2=A0=
=C2=A0 &quot;);&#39;</tt></p>
    <p>You will get an experimental warning, but the function should
      work and remove the whitespace.<br>
    </p>
    <p>- Scottchiefbaker<tt><br></tt></p></div></blockquote></div></blockqu=
ote><div><br></div><div>I&#39;ve added some comments on Github but overall =
I&#39;d love to see such a function!</div><div>Control over what characters=
 should be trimmed would be awesome and default to what it currently does.<=
/div><div>That way you could also use it to trim brackets for example.<br><=
/div></div></div>

--000000000000cb5b0e05aaf8e463--
0
alex
7/21/2020 7:47:19 PM
--0000000000007778af05aaf903e4
Content-Type: text/plain; charset="UTF-8"

On Tue, Jul 21, 2020 at 3:47 PM Alexander Hartmaier <
alex.hartmaier@gmail.com> wrote:

> On Tue, Jul 21, 2020 at 8:35 PM Eric Brine <ikegami@adaelis.com> wrote:
>
>> Having a function to trim both ends but not one to trim trailing
>> whitespace is really weird to me. Virtually every program I write needs the
>> latter (though I usually settle for chomp).
>>
>> On Tue, Jul 21, 2020 at 1:59 PM Scott Baker <scott@perturb.org> wrote:
>>
>>> It's been a personal pet peeve of mine that Perl has never had a
>>> *trim()* function in core. After discussion
>>> <https://github.com/Perl/perl5/issues/17952> with Grinnz, Leonerd, and
>>> others we decided to move forward with seeing what it would take to add it
>>> to core. I wrote documentation and tests, and LeoNerd wrote the actual
>>> implementation. Now I'm here soliciting feedback on this feature before I
>>> submit a formal PR.
>>>
>>> You can checkout my branch here:
>>> https://github.com/scottchiefbaker/perl5/tree/trim
>>>
>>> Once it's built the easier way to test it is: ./perl -Ilib -E 'say
>>> CORE::trim("   Hello world!    ");'
>>>
>>> You will get an experimental warning, but the function should work and
>>> remove the whitespace.
>>>
>>> - Scottchiefbaker
>>>
>>
> I've added some comments on Github but overall I'd love to see such a
> function!
> Control over what characters should be trimmed would be awesome and
> default to what it currently does.
> That way you could also use it to trim brackets for example.
>

Control over what is trimmed was discussed in the ticket, summarized here:
https://github.com/Perl/perl5/issues/17952#issuecomment-658462652

Ultimately we decided at least for now it is too much complication without
an obvious and simple form the interface should take - and it is simple to
do this with custom regexes should you need something slightly different.

-Dan

--0000000000007778af05aaf903e4
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr">On Tue, Jul 21, 2020 at 3:47 PM Alexander=
 Hartmaier &lt;<a href=3D"mailto:alex.hartmaier@gmail.com">alex.hartmaier@g=
mail.com</a>&gt; wrote:<br></div><div class=3D"gmail_quote"><blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid =
rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div class=3D"gmail_quo=
te"><div dir=3D"ltr" class=3D"gmail_attr">On Tue, Jul 21, 2020 at 8:35 PM E=
ric Brine &lt;<a href=3D"mailto:ikegami@adaelis.com" target=3D"_blank">ikeg=
ami@adaelis.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" s=
tyle=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);pad=
ding-left:1ex"><div dir=3D"ltr">Having a function to trim both ends but not=
 one to trim trailing whitespace is really weird to me. Virtually every pro=
gram I write needs the latter (though I usually settle for chomp).<br></div=
><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Tu=
e, Jul 21, 2020 at 1:59 PM Scott Baker &lt;<a href=3D"mailto:scott@perturb.=
org" target=3D"_blank">scott@perturb.org</a>&gt; wrote:<br></div><blockquot=
e class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px s=
olid rgb(204,204,204);padding-left:1ex">
 =20

   =20
 =20
  <div>
    <p>It&#39;s been a personal pet peeve of mine that Perl has never had a
      <b>trim()</b> function in core. After <a href=3D"https://github.com/P=
erl/perl5/issues/17952" target=3D"_blank">discussion</a>
      with Grinnz, Leonerd, and others we decided to move forward with
      seeing what it would take to add it to core. I wrote documentation
      and tests, and LeoNerd wrote the actual implementation. Now I&#39;m
      here soliciting feedback on this feature before I submit a formal
      PR.</p>
    <p>You can checkout my branch here:
      <a href=3D"https://github.com/scottchiefbaker/perl5/tree/trim" target=
=3D"_blank">https://github.com/scottchiefbaker/perl5/tree/trim</a></p>
    <p>Once it&#39;s built the easier way to test it is: <tt>./perl -Ilib
        -E &#39;say CORE::trim(&quot;=C2=A0=C2=A0 Hello world!=C2=A0=C2=A0=
=C2=A0 &quot;);&#39;</tt></p>
    <p>You will get an experimental warning, but the function should
      work and remove the whitespace.<br>
    </p>
    <p>- Scottchiefbaker<tt><br></tt></p></div></blockquote></div></blockqu=
ote><div><br></div><div>I&#39;ve added some comments on Github but overall =
I&#39;d love to see such a function!</div><div>Control over what characters=
 should be trimmed would be awesome and default to what it currently does.<=
/div><div>That way you could also use it to trim brackets for example.<br><=
/div></div></div></blockquote><div><br></div><div>Control over what is trim=
med was discussed in the ticket, summarized here:=C2=A0<a href=3D"https://g=
ithub.com/Perl/perl5/issues/17952#issuecomment-658462652">https://github.co=
m/Perl/perl5/issues/17952#issuecomment-658462652</a></div><div><br></div><d=
iv>Ultimately we decided at least for now it is too much complication witho=
ut an obvious and simple form the interface should take - and it is simple =
to do this with custom regexes should you need something slightly different=
..</div><div><br></div><div>-Dan</div></div></div>

--0000000000007778af05aaf903e4--
0
grinnz
7/21/2020 7:55:49 PM
Reply: