LinguaFranca
Technical User
Hello,
I try to compare the hash keys of two individual files.
The content of file1 is (tab separated columns):
Carmen !
Poekie
This is a test .
Winter ?
Test !
The content of file2 is (tab separated columns):
this is a test test.res, bla.frm
carmen test.res, carmen,txt
poekie poeki.frm
The desired output should be:
This is a test . test.res, bla.frm
Carmen ! test.res, carmen.txt
Poekie poekie.frm
NO MATCH: Winter ?
NO MATCH: TEST !
My problem is that the while construct loops through file1 without starting the comparison line by line. It only takes the last line of file1. This is the current output:
NO MATCH: Test !
NO MATCH: Test !
NO MATCH: Test !
Please, be patient, I am still learning Perl. Hope you can help me.
Here's the code snippet I wrote:
I try to compare the hash keys of two individual files.
The content of file1 is (tab separated columns):
Carmen !
Poekie
This is a test .
Winter ?
Test !
The content of file2 is (tab separated columns):
this is a test test.res, bla.frm
carmen test.res, carmen,txt
poekie poeki.frm
The desired output should be:
This is a test . test.res, bla.frm
Carmen ! test.res, carmen.txt
Poekie poekie.frm
NO MATCH: Winter ?
NO MATCH: TEST !
My problem is that the while construct loops through file1 without starting the comparison line by line. It only takes the last line of file1. This is the current output:
NO MATCH: Test !
NO MATCH: Test !
NO MATCH: Test !
Please, be patient, I am still learning Perl. Hope you can help me.
Here's the code snippet I wrote:
Code:
#!usr/bin/perl
use locale;
open FILE1, "file1.ans" or die;
open FILE2, "file2.ans" or die;
while (<FILE1>) {
chomp;
($orig, $punct)=(split (/\t/), $_) [0,1];
$orig{$orig}=$_;
}
close FILE1;
while (<FILE2>) {
chomp;
($klein, $files) = split (/\t/);
$kleinarr{$klein}=$files;
if (lc($orig) eq $klein) {
print "$orig{$orig}\t$kleinarr{$klein}\n";
} else {
print "NO MATCH:\t$orig\t$punct\n";
}
}
close FILE2;
exit;