두 개의 텍스트 파일이 있는데 두 번째 열의 파일간에 불일치를 찾고 싶습니다. 식별 될 불일치는 발생하는 행에 관계없이 유형이 F ,P and N
인 것을 기]으로합니다. 첫 번째 파일에는 1F, 3P가 있고 두 번째 파일에는 2P, 1N 및 1F가 있습니다. 비교할 때 두 파일 모두 1F, 3P 및 1N 유형의 동일한 발생이 있어야합니다.두 번째 텍스트 파일 사이의 두 번째 열에서 불일치 찾기
텍스트 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