开发者

Perl equivalent of PHP's preg_callback

开发者 https://www.devze.com 2022-12-29 23:00 出处:网络
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

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

精彩评论

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

关注公众号