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

Re: trim vs trimmed revisited

Thread Previous | Thread Next
David Nicol
February 25, 2022 18:14
Re: trim vs trimmed revisited
Message ID:
hmm. I may just be being difficult, having internal featuritis. I'd like to
be able to trim arrayrefs and hashrefs at once, recursively, either
in-place or making a deep copy, depending. But without causing trouble.
Almost mentally healthy enough to delete this without sending.

 sub trim {
      if (wantarray){
              my @ret = @_;
              return @ret;
      }elsif (defined wantarray){
              my $t = shift;
              return $t;

      # something about dealing with references here?

      s/\s*(.*?)\s*\z/$1/s for @_;

> What does this do?
>   sub shortname {
>      my $self = shift;
>      return trim( $self->{fullname} );
>   }

Causes problems. Should raise a warning or not even compile. Better written
like so:

  sub shortname {
     my $self = shift;
     return my $dummy = trim( $self->{fullname} );

or maybe

 sub shortname {
     my $self = shift;
     "@{[trim( $self->{fullname}]}";

"Lay off that whiskey, and let that cocaine be!" -- Johnny Cash

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About