in reply to using functions within regex
Are you looking for the /e option? (See perlre and perlretut). Here's an example, in action:
use 5.010_001; use strict; use warnings; my $string = "It's hard to teach an old dog new tricks."; $string =~ s/(dog)/reverse($1)/e; say $string;
The output: "It's hard to teach an old god new tricks." What's happening here is the right-hand side is being evaluated as code. The code should return a string which will serve as the replacement string.
Dave
|
|---|