Skip to content

Instantly share code, notes, and snippets.

@soren
Created October 15, 2014 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soren/e8fb3fb5175646bcb5b6 to your computer and use it in GitHub Desktop.
Save soren/e8fb3fb5175646bcb5b6 to your computer and use it in GitHub Desktop.
#!/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