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

Andy Lester andy at petdance.com
Mon Mar 13 14:23:27 PST 2006


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

map returns the list that it got done processing.  If you're not  
using the result, then use for().  It's not an efficiency thing,  
although at one point it was.  It's just more idiomatic.

s/\s+$// for @j;

> map { s/\s+$// } @j;
>
> print join "|", @j;
> print "\n";

In your case, you could do this:

print join( "|", map { s/\s+$// } @j ), "\n";

Note that in both cases, you're modifying the contents of @j.   
Modifying $_ in a loop like this modifies the original item. If you  
just wanted to capitalize things, you could do this:

print join( "|", map { lc } @j );

That would leave the original contents of @j unmolested.

--
Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance





More information about the Omaha-pm mailing list