- 论坛徽章:
- 0
|
本帖最后由 zhlong8 于 2013-09-12 13:05 编辑
有三个文件file1, part1, part2.根据用户输入的信息要更新part1,part2然后将更新好的内容插入file1指定位置,产生file2. 用户会输入多行数据,所以会有多次插入。每一次插入要在前一次插入后的基础上改。因为file1要做为模板继续使用,所以要产生一个新文件。我现在的做法每插入一次就产生一个文件名后面加01的新文件,想求助各位有没有办法在第一次插入后产生新文件,之后的插入就在原文件改动呢?
sub CPInsert{
my $file1 = shift;
my $file2 = $file1 ."01";
open(PART1,"<","$cwdpath\\part1_update.sql") or die "Cannot open $cwdpath\\part1_update.sql:$!\n";
open(PART2,"<","$cwdpath\\part2_update.sql") or die "Cannot open $cwdpath\\part2_update.sql:$!\n";
my @part1lines = <PART1>;
my @part2lines = <PART2>;
close(PART1);
close(PART2);
open(TMP,"<","$cwdpath\\$file1.sql") or die "Cannot open $cwdpath\$file1.sql:$!\n";
open(RESULT,">","$cwdpath\\$file2.sql") or die "Cannot open $cwdpath\$file2.sql:$!\n";
while(<TMP>){
if($_ =~ m/integration\('N'\)[\s\S]*/){
print RESULT @part1lines;
}
print RESULT $_;
}
print RESULT @part2lines;
close(TMP);
close(RESULT);
return $file2;
}
主程序循环里用 $file = CPInsert("$file"); |
|