Perlfunc: trim()

Perl function to trim leading and trailing whitespace, borrowed from String::Util.

sub trim {
    my $s = shift();

    if (!defined($s)) {
        return undef;

    $s =~ s/^\s*//u;
    $s =~ s/\s*$//u;

    return $s;

To trim an each item in an array you can do:

@array = map { trim($_) } @array;

Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
Logged IP:
To prevent spam please submit by clicking the kitten: