RosettaCodeData/Task/Higher-order-functions/Perl/higher-order-functions-2.pl
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

8 lines
416 B
Perl

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