Created
October 15, 2014 12:25
-
-
Save soren/e8fb3fb5175646bcb5b6 to your computer and use it in GitHub Desktop.
Perl version of https://github.com/soren/list-trim-demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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