develooper Front page | perl.perl5.porters | Postings from April 2010

Re: trim function example for perlfaq4.pod

Thread Previous
From:
Ævar Arnfjörð Bjarmason
Date:
April 9, 2010 16:40
Subject:
Re: trim function example for perlfaq4.pod
Message ID:
k2r51dd1af81004091640t2f945b3bvc225ccc03e24dbe0@mail.gmail.com
On Fri, Apr 9, 2010 at 23:12, David Nicol <davidnicol@gmail.com> wrote:
> +   use constant Regexp_type => ref qr/bzzt/;
> +   sub trim{
> +     my $R = (ref $_[-1] eq Regexp_type ? pop : qr/\s/ );
> +     @_ or return trim($_,$R);
> +     wantarray and return map { s/\A$R+//; s/$R+\Z//; $_ } my @copy = @_;
> +     defined wantarray and return do {
> +        my $copy = shift;
> +        @_ and Carp::croak 'too many arguments for trim in scalar context';
> +        $copy =~ s/\A$R+//; $copy =~ s/$R+\Z//; $copy;
> +     };
> +     do { s/\A$R+//; s/$R+\Z// }  for  @_;
> +   }
> +

perl5-porters doesn't maintain the perlfaq. I believe these days that
the best way to submit patches is to fork the GitHub repository at
http://github.com/briandfoy/perlfaq/

In my opinion this example is a bit too terse to be in the perlfaq. I
think it would be the longest code example in perlfaq4.pod. Is this
really the sort of thing people should be encouraged to copy/paste to
their programs instead of just using Text::Trim or some other module?

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About