I have
my $x = "whatever 123";
$x =~ s/ //g;
$x =~ s/\d/9/g;
frobnicate($x);
although in real life it’s far messier and bigger. What I would like to do is perform the substitions in functional form, like this:
my $x = "whatever 123";
frobnicate( regex_substitutions($x, s/ //g, s/\d/9/g) );
That may look like a step backward in readability, but in real life something like this would actually help. The goal it to avoid having the regex substitutions in separate statements, but incorporated into an expression. I’m guessing there’s a slick and readable way to do this that long-time perl experts would know.
(Not only is there “more than one way to do it” but there’s more than one way to ask about any particular thing. Forgive me if this question is redundant with existing ones.)
5.14 introduced /r(eturn):
Any version:
applycomes from List::MoreUtils.