Friday, October 30, 2015

Perl Hack: Modifying a List

One of my favorite Perl hacks, shown to me by a work colleague a few years ago, is for modifying a list. The hack is actually fairly pretty:

s/^ +//g, s/ +$//g for @list;

For very simple substitutions, I think this is more expressive and easier to understand than the usual foreach loop, or a map.

No comments:

Post a Comment