- 论坛徽章:
- 0
|
#!/usr/bin/perl -w
use strict;
our $WORK_PATH = $ARGV[0];
#my $dir = "d:\\test\\";
open(FILE_A,"$WORK_PATH/A.txt") || die;
my @in_a=<FILE_A>;
close(FILE_A);
open(FILE_B,"$WORK_PATH/B.txt") || die;
my @in_b=<FILE_B>;
close(FILE_b);
open my $out , ">$WORK_PATH/C.txt" or die;
foreach my $tmpb (@in_b)
{
chomp($tmpb);
our $tmpb1 = substr($tmpb,rindex($tmpb,':')+1);
print "$tmpb1","\n";
our $tmpb2 = substr($tmpb,0,rindex($tmpb,':'));
print "$tmpb2","\n";
foreach (@in_a)
{
chomp;
print "$tmpb2\n";
print "$tmpb1\n";
my $temp =~ s/$tmpb2/$tmpb1/;
print "$temp\n";
print $out "$temp\n";
}
last;
}
A文件:
10.1.1.1 xxxxxxxx
10.1.1.2 xxxxxxxx
10.1.1.3 zzzzzzzz
10.1.1.4 xxxxxxxx
10.1.1.5 xxxxxxxx
10.1.1.6 xxxxxxxx
10.1.1.7 yyyyyyyy
10.1.1.8 xxxxxxxx
10.1.1.9 yyyyyyyy
10.1.1.10 yyyyyyy
B:
xxxxxxxx:你欠水费
yyyyyyyy:你欠电费
zzzzzzzz:你欠气费
现在要把xxxxxxxx yyyyyyyy zzzzzzzz 替换成响应的文字。 s/$tmpb2/$tmpb1/ 怎么不起效? |
|