- 论坛徽章:
- 0
|
原帖由 juming1983 于 2009-12-19 07:21 发表 ![]()
各位大大,有两个文件,如1.txt,2.txt
1.txt有以下数据:
123456,192.162.11.2
123457,192.162.11.20
............
2.txt有以下数据
BJ 192.162.11.2
AU 192.162.11.20
..............
我想将两个文件 ...
#!/usr/bin/perl
%one=();
open FH,"1.txt" or die "cannot open $! \n";
while (<FH>){
chomp;
($name,$ip)=split(/,/);
#print "$ip";
$one{$ip}=$name;
}
close FH;
open FH1,"2.txt" or die "cannot open $! \n";
while (<FH1>){
chomp;
($country,$ip)=split(/ /);
if (exists $one{$ip}) {
print "$one{$ip} $ip $country \n";
}
}
close FH1;
这样行吗? |
|