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

Re: trim function example for perlfaq4.pod

Thread Previous | Thread Next
From:
brian d foy
Date:
April 11, 2010 05:43
Subject:
Re: trim function example for perlfaq4.pod
Message ID:
110420101442522830%brian.d.foy@gmail.com
In article
<t2v934f64a21004091612hb8095399q63d43deeb92c1a5a@mail.gmail.com>, David
Nicol <davidnicol@gmail.com> wrote:

> diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod
> index f671b62..8a84490 100644
> --- a/pod/perlfaq4.pod
> +++ b/pod/perlfaq4.pod
> @@ -928,6 +928,27 @@ you have to do a little more work. Instead of matching
> any
>  (since that includes a newline), just match the other whitespace.
> 
>         $string =~ s/^[\t\f ]+|[\t\f ]+$//mg;
> +
> +(contributed by David Nicol)
> +
> +Here is a trim function that operates in-place in void context, in-line

For the FAQ, I think this would be much nicer if it wasn't too clever
and it explained more about what it did. Remember the level of the FAQ
reading audience. :)

However, even better than your example would be something where no one
had to see that complexity. 

     use String::Trim; # doesn't exist yet?
     my $trimmed = trim qr/.../, $string;

People really aren't asking how to implement a trim, they just want to
get something that will trim. :)

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