This, and BrowserUk's suggestion are both good ones. BrowserUk's I wasn't even aware of, and this one I had somewhat forgot about. However, I do like the consistency of having one method of doing it that works both standalone and in map. Although I usually argue that adding a variable at the end of a map block isn't that bad, I'm going to be a devil's advocate and argue against it here.
my @output = map { (my $i = $_) =~ s/foo/bar/; $i } @input;
Seems less readable to me than
my @output = map { $_ \~ s/foo/bar/ } @input;
And I like the use of 'map' instead of 'filter' (especially since I think of grep when I think of filter).
I guess it looks like personal preference here, so maybe I'll just perfect this one and keep it for myself (since I don't use $1 and $2 very often from what I've noticed, I wouldn't have to fix them just for myself).
-Bryan
In reply to Re^2: A Functional Substitute
by mrborisguy
in thread A Functional Substitute
by mrborisguy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |