perl 在我的字符串中搜索数字 [英] perl search digits in my string
本文介绍了perl 在我的字符串中搜索数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的字符串中的搜索数字有问题.我有两个文件.
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);
问题是:如何找到数字(256 和 110)进行增量和保存文件.例如,字符串定义('upd_ver',256);保存后变成define('upd_ver', 257);
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);
推荐答案
一种方法:
s/(define\(.*?,\s*)(\d+)/"$1" . ($2 + 1)/eg;
/e
标志导致对替换字符串进行评估,并替换其 结果,而不是替换字符串本身被简单地作为文字插入字符串.
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.
这篇关于perl 在我的字符串中搜索数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文