Perl equivalent of PHP's preg_callback
Do we have a preg_callback equivalent in Perl ?
Lets say I w开发者_开发问答ant 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
精彩评论