Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/env perl
use warnings;
use strict;
my $line = "one,two, three, four , five ";
sub print_list {
printf "[%s]\n", join(', ', @_);
}
print_list split /,/, $line;
print_list map { s/^\s+|\s+$//g; $_ } split /,/, $line;
sub trim {
(my $trimmed = shift) =~ s/^\s+|\s+$//g;
return $trimmed;
}
print_list map { trim($_) } split /,/, $line;
# http://search.cpan.org/~miko/String-Util-1.23/lib/String/Util.pm
# http://search.cpan.org/~pevans/Scalar-List-Utils-1.39/lib/List/Util.pm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment