开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜