求助perl 代码合并生成一个文件--谢谢

求助perl 代码合并生成一个文件--谢谢

a.txt

.ic v(o<0> )=0
.ic v(o<1> )=0
.ic v(o<2> )=0
.ic v(o<3> )=0
.ic v(o<4> )=0
.ic v(o<5> )=0
.ic v(o<6> )=0

b.txt

(xddr_model2.xi1.xzhalf2.260)
(xddr_model2.xi1.xzhalf2.261)
(xddr_model2.xi1.xzhalf2.264)
(xddr_model2.xi1.xzhalf2.26
(xddr_model2.xi1.xzhalf2.269)
(xddr_model2.xi1.xzhalf2.270)

上面是两个文件的内容,我想生成一个c.txt具体格式如下:

.ic v(xddr_model2.xi1.xzhalf2.260) =0
.ic v(xddr_model2.xi1.xzhalf2.261) =0
.ic v(xddr_model2.xi1.xzhalf2.264) =0
.ic v(xddr_model2.xi1.xzhalf2.26 =0
.ic v(xddr_model2.xi1.xzhalf2.269) =0
.ic v(xddr_model2.xi1.xzhalf2.270) =0

我想用perl生成这个c.txt文件,
谢谢大家的帮助

#!/usr/bin/perl

use strict;
use warnings;

open A_FILE, 'a.txt'
    or die;

open B_FILE, 'b.txt'
    or die;

open C_FILE, ">c.txt"
    or die;

while (<A_FILE>) {
    chomp(my $t = <B_FILE>);
        s/o<\d>/\Q$t\E/;
        print C_FILE $_;
}


——————————————————————
没调试,不知道有没有错误。
#!/usr/bin/perl
use strict;
use warnings;
open A_FILE, 'a.txt' or die;
open B_FILE, 'b.txt' or die;
open C_FILE, ">c.txt" or die;
while (<A_FILE>) {
    my $t = <B_FILE>;
        s/o<\d>/\Q$t\E/;
        print C_FILE $_;
}

执行后error

Use of uninitialized value in quotemeta at ./test.pl line 9, <B_FILE> line 6.
Use of uninitialized value in quotemeta at ./test.pl line 9, <B_FILE> line 6.
Use of uninitialized value in quotemeta at ./test.pl line 9, <B_FILE> line 6.


c.txt 输出入下

.ic v(\.ic\ v\(xddr_model2\.xi1\.xzhalf2\.260\)\=0\
)=0
.ic v(\.ic\ v\(xddr_model2\.xi1\.xzhalf2\.261\)\=0\
)=0
.ic v(\.ic\ v\(xddr_model2\.xi1\.xzhalf2\.264\)\=0\
)=0
.ic v(\.ic\ v\(xddr_model2\.xi1\.xzhalf2\.268\)\=0\
)=0
.ic v(\.ic\ v\(xddr_model2\.xi1\.xzhalf2\.269\)\=0\
)=0
.ic v(\.ic\ v\(xddr_model2\.xi1\.xzhalf2\.270\)\=0\
)=0
.ic v()=0
.ic v()=0
顶一下
刚才想多了

#!/usr/bin/perl

use strict;
use warnings;

open A_FILE, 'a.txt'
    or die;

open B_FILE, 'b.txt'
    or die;

open C_FILE, ">c.txt"
    or die;

while (<A_FILE>) {
    chomp(my $t = <B_FILE>);
        s/\(o<\d>\s+\)/$t/;
        print C_FILE $_;
}


——————————————

你 a 和 b 不是一一对应的吗,a 长 b 短 啊
谢谢我搞定了,谢谢
既然不一样长,这样好些

#!/usr/bin/perl

use strict;
use warnings;

open A_FILE, 'a.txt'
    or die;

open B_FILE, 'b.txt'
    or die;

open C_FILE, ">c.txt"
    or die;

while (<B_FILE>) {
    chomp;
        my $t = <A_FILE>;
   
        $t =~ s/\(o<\d>\s+\)/$_/;
   
        print C_FILE $t;
}
是的,长短不一样,但还是不行,我感觉还是

$t =~ s/\(o<\d>\s+\)/$_/; 这句有问题

生成c.txt如下
.ic v(o<0>)=0
.ic v(o<1>)=0
.ic v(o<2>)=0
.ic v(o<3>)=0
.ic v(o<4>)=0
.ic v(o<5>)=0
.ic v(o<6>)=0
.ic v(o<7>)=0


和a.txt一样了


谢谢,还是有问题。。。Thanks

#!/usr/bin/perl
use warnings;
use strict;

my @r;
open FILE1,"b.txt";
open FILE2,">","c.txt";

while(<FILE1>)
{
    chomp;
    push @r,$_ if /(\(.*\))/;
}

foreach (@r)
{
    print FILE2 ".ic v".$_," =0\n";
}
我的大致解法,大致测试了一下通过了

open A,"<a.txt";
open B,"<b.txt";
open C,">c.txt";
chomp(@b=<B>);
while(<A>) {
        s/\(.*\)/$b[$.]/;
        print C "$_";
}