问题
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