[Omaha.pm] map {} one-liner that removes trailing spaces

Jay Hannah jhannah at omnihotels.com
Mon Mar 13 12:44:33 PST 2006


(I'm still not a daily map user, but maybe I'm getting there?)

perldoc -f map


Answer:
---------
map { s/\s+$// } @j;


Demo code:
---------
$ cat j.pl
my @j = ("a  ", "b  ", "c  ");
print join "|", @j;
print "\n";

map { s/\s+$// } @j;

print join "|", @j;
print "\n";


Demo run:
---------
$ perl j.pl
a  |b  |c
a|b|c


Cheers,

j


More information about the Omaha-pm mailing list