RosettaCodeData/Task/Higher-order-functions/Perl/higher-order-functions-2.pl

9 lines
416 B
Perl
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
sub apply (&@) { # use & as the first item in a prototype to take bare blocks like map and grep
my ($sub, @ret) = @_; # this function applies a function that is expected to modify $_ to a list
$sub->() for @ret; # it allows for simple inline application of the s/// and tr/// constructs
@ret
}
print join ", " => apply {tr/aeiou/AEIOU/} qw/one two three four/;
# OnE, twO, thrEE, fOUr