请教:合并文档

请教:合并文档

file 1

section mos_ro
model nenhro  bsim3v3 type = n  
endsection mos_ro
*
*
section res
******************************************************
.subckt rnwsti n1 n2 l=length w=width
parameters rsh=rsh_rnwsti  dw=0.35u ptc1=4.3e-3 ptc2=0 pvc1=1.4e-02 pvc2=0 pt=temper
parameters tfac=1.0+ptc1*(pt-25.0)+ptc2*(pt-25.0)*(pt-25.0)
r1 n1 n2 rsh*l/(w-dw)*(1+pvc1*abs(v(n2,n1))+pvc2*v(n2,n1)*v(n2,n1))*tfac
.ends rnwsti
endsection res

section pip
endsection pip


file2


section res
******************************************************
ahdl_include "res_mod.va"

subckt rnwsti n1 n2
parameters w=1u l=1u
r1 (n1 n2) res_mod w=w l=l r=rsh_rnwsti dw=0.35u tc1=4.3e-3 tc2=0 vc1=1.4e-02 vc2=0
ends rnwsti

endsection res


希望将file2文件中内容替换file1中 section  res 和 endsection res之间的内容
perl test.pl file1 file2

#!/usr/bin/perl -w
use strict;

my$File_1 = $ARGV[0];
my$Backup = $ARGV[0] . ".orig";
my$File_2 = $ARGV[1];

rename $File_1 ,$Backup;
open IN,$Backup;
open IN1,$File_2;
open OUT,">",$File_1;
my @r = <IN1>;

my $flag = 1;
my $flag1 = 1;
while(<IN>){
    $flag = 0 if /^section res/;
    $flag = 1 if /^endsection res/;
    print OUT $_ if $flag && $_ !~ /^endsection res/;
    if($flag == 0 && $flag1 == 1){
        print OUT @r;
        $flag1 = 0;
    }
}
非常感谢!!