Gunnar Hjalmarsson wrote:

sub trim {
    for ( $_[0] ) {
        s/^\s+//;
        s/\s+$//;
    }
}

The following respects the environment better. :)

sub trim {

    if ( defined wantarray() ) {

        my @_s = @_;  # copy

        s/\s+$//, s/^\s+//
            for grep defined(), @_s;

        return wantarray() ? @_s : $_s[0];
    }

    s/\s+$//, s/^\s+//
        for grep defined(), @_;  # in place

    return;
}

--
Ruud

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to