perl search digits in my string

馋奶兔 提交于 2019-12-14 02:09:44

问题


I have problem with search digits in my string. I have two files.

stver.php

define('upd_ver', 256); 

tr_ver.php

define('code_ver', 110);

The problem is: how to find digits (256 and 110) make increment and save files. Exmpl, string define('upd_ver', 256); after saving becomes define('upd_ver', 257);

#!/usr/bin/perl
$sv="stver.php";
$tv="tr_ver.php";
open (SVIN, $sv) || die "Can't open $sv";
while (<SVIN>)
{ chomp; print;}
print "\n";
close (SVIN); 

回答1:


One approach:

s/(define\(.*?,\s*)(\d+)/"$1" . ($2 + 1)/eg;

The /e flag causes the replacement-string to be evaluated, and its result substituted in, rather than the replacement-string itself being simply plopped in as a literal string.



来源:https://stackoverflow.com/questions/9415946/perl-search-digits-in-my-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!