[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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@petdance.com => www.petdance.com => AIM:petdance