develooper Front page | perl.perl5.porters | Postings from February 2022

Re: trim vs trimmed revisited

Thread Previous | Thread Next
From:
Christian Walde
Date:
February 25, 2022 18:32
Subject:
Re: trim vs trimmed revisited
Message ID:
op.1h5sf2d3ydyjqt@xenbox.cihq
On Fri, 25 Feb 2022 19:20:01 +0100, David Nicol <davidnicol@gmail.com> wrote:
>> Compare:
>>
>>     my @trimmed = map trim, @strings;   # trim called in array context
>>
>>     my @trimmed = map { trim( my $trimmed = $_ ); $trimmed } @strings;  # trim called in void context
>
> Is it set in stone yet that trim takes only one arg (has a ($) prototype)?
>
> Compare:
>
>    my @trimmed = trim @strings;  # handling multiple arguments is orthogonal to in-place or not

I appreciate the question, but this is a good example of not thinking far enough in terms of UX. :)

Even if we were to "optimize" list processing into a list argument call, that was a standin, because list processing has many shapes.

     my @filtered = map { preserve_spaces($_) ? $_ : trim $_ } @strings;

     my @filtered = map { preserve_spaces($_) ? $_ : do { trim( my $trimmed = $_ ); $trimmed  } } @strings;

-- 
With regards,
Christian Walde
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