Do we have a preg_callback equivalent in Perl ?
Lets say I want to match something and replace it with the return value of the function that is called with the matched thing.
Use s///e
- evaluation modifier and you can put arbitrary perl codes in second part.
$x = "this is a test";
$x =~ s/(test)/reverse($1)/eg;
print $x;
//this is a tset
ref: http://perldoc.perl.org/perlretut.html#Search-and-replace
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With