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

Re: trim function example for perlfaq4.pod

Thread Previous | Thread Next
brian d foy
April 11, 2010 05:43
Re: trim function example for perlfaq4.pod
Message ID:
In article
<>, David
Nicol <> 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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About