這個問題是cu上有人提出的,感受具備表明性,特意記錄一下web
好比a 文件 內容以下
a=11 b=http://www.baidu.com/baicd c=xxx/baidu.apk
a=12 b=http://www.sina.com/xxx c=xxx/sina.apk
a=13 b=http://www.qq.com/sdfsd c=xxx/qq.akc
b 文件內容以下
www.baidu.com,111
www.sina.com,112
c 文件內容以下
baidu.apk,123
sina.apk,12223
結果
11,http://www.baidu.com/baicd ,111,123
12,http://www.sina.com/xxx ,112,12223
13,http://www.qq.com/sdfsd ,qq.akc,,sql
- use strict;
- use warnings;
- use Data::Dumper;
- my (%hash1,%hash2);
- open FC,"c.txt" or die "$!";
- while(<FC>){
- chomp; #把C文件映射爲HASH表,用於替換
- /(\S+),(\S+)/;
- $hash2{$1}=$2;
- }
- close FC;
- open FA,"a.txt" or die "$!";
- while(<FA>){
- my($num,$url,$domain,$apk1);
- s/a=(\d+)\s+\w+=(http:\/\/([^\/]+)\/\S+)\s+[^\/]+\/(\S+)/
- ($num,$url,$domain,$apk1)= ($1,$2,$3,$4);
- /xeg;
- $apk1 =~ s/($apk1)/$hash2{$1}? $hash2{$1}:"$1"/eg;
- push @{$hash1{$domain}},$num,$url,$apk1;
- }
- open FB,"b.txt" or die "$!";
- while(<FB>){
- chomp;
- /(\S+),(\S+)(?{push @{$hash1{$1}},$2})/;
- }
- close FB;
- for (sort keys%hash1){
- my @arr;
- unless(defined$hash1{$_}[3]){
- push @arr ,$hash1{$_}[0],$hash1{$_}[1],$hash1{$_}[2],",",;
- }else{
- push @arr ,$hash1{$_}[0],$hash1{$_}[1],$hash1{$_}[3],$hash1{$_}[2];
- }
- print join(",",@arr)."\n";
- }
- output
- 11,http://www.baidu.com/baicd,111,123
- 13,http://www.qq.com/sdfsd,qq.akc,,
- 12,http://www.sina.com/xxx,112,12223