我有這2個文本文件,我想找到任何不匹配的文件之間的第二列。不確定性是基於F ,P and N
的類型,而不管它們出現在哪一行。第一個文件中有1F,3P,第二個文件中有2P,1N和1F。兩種文件在進行比較時,應該具有1F,3P和1N類型的相同值。找到2個文本文件之間的第二列不匹配
文本1:
f0x11 F
f0x34 P
drx99
dex67 P
edx43 P
sdx33
文本2:
1 P
2 N
4
5 F
6
7 P
預期輸出:
Text 1 has missing type of N
Text 2 has missing type of P
我至今嘗試不會產生所需的輸出。
代碼:
use strict;
my %ref_data;
my %ref_data2;
open my $fh, '<', 'Text1' or die "Could not open file to read:$!";
while (<$fh>) {
chomp;
my ($res, $type) = split;
if (defined $type){
$ref_data{$type} = "$type";
}
}
our ($data,$data2);
open $fh, '<', 'Text2' or die "Could not open file to read:$!";
while (<$fh>) {
chomp;
my ($res, $type) = split;
if (defined $type){
$ref_data2{$type}= "$type";
$data2= $ref_data2{$type};
$data = $ref_data{$type};
print "File 2 has missing type of $type\n" unless $data;
}
}
foreach ($data){
print "File 1 has missing type of $_\n" if $data ne $data2;
}
請不要告訴我。提前致謝。 – annel
我沒有看到你如何從你的示例輸入中獲得預期的輸出。你的兩個輸入文件都有一個F,只有不同的行:爲什麼你的輸出說只有其中一個有一個「缺少類型的F」? –
@llmari這是錯字錯誤。 – annel