+ -
当前位置:首页 → 问答吧 → 求助:Perl脚本批量修改cgi文件中的语句!

求助:Perl脚本批量修改cgi文件中的语句!

时间:2011-08-23

来源:互联网

问题描述:
在一个CGI脚本 a.cgi 中,有大量的包含语句,其中一些包含select的语句,如下:

$stkn4= $dbh->prepare("select PRNR from ufh where LANG_ID =cn");
$stkn2= $dbh->prepare("select Num from knr where Num_ID =DW and KK=14");
$sth= $dbh2->prepare("select teile_string from fh02t05 where wk=1 and sj=15 and ss=12");

需要在每条完整的select语句后,加入with UR。变成如下:

$stkn4= $dbh->prepare("select PRNR from ufh where LANG_ID =cn with UR");
$stkn2= $dbh->prepare("select Num from knr where Num_ID =DW and KK=14 with UR");
$sth= $dbh2->prepare("select teile_string from fh02t05 where wk=1 and sj=15 and ss=12 with UR");


脚本中单独的select字符不用管,只对select语句起作用。

求perl正则表达式或者脚本,来批量解决这样的问题!

谢谢!

作者: baohuanyu   发布时间: 2011-08-23

Perl code
s/"(select.*from*)"/"\1 with UR"/g;


最简单的做法(大概这个意思,没测试过)。
修改前自己先review下替换结果。这个简单的脚本有很多特殊情况处理不了。

作者: iambic   发布时间: 2011-08-23