Simple comparison with Perl

#!/usr/bin/perl

system "cat dict1.raw | awk {'print $1'} | uniq | sed 's/^[[:upper:]].*//g' > dict1";
system "cat dict2.raw | awk {'print $1'} | uniq | sed 's/^[[:upper:]].*//g' > dict2";

$dict1 = "dict1";
$dict2 = "dict2";

open (DICT1, $dict1) || die ("Could not open file!");
open (DICT2, $dict2) || die ("Could not open file!");

@dictionary_1 = <DICT1>;
@dictionary_2 = <DICT2>;

@equal = ();
@diff = ();
%count = ();

foreach $word (@dictionary_1, @dictionary_2) { $count{$word}++; }
foreach $word (keys %count) {
if ($count{$word} == 2) {
    push @equal, $word;
} else {
    push @diff, $word;
    }
}

print "\nDict1 = \n @dictionary_1\n";
print "\nDict2 = \n @dictionary_2\n";
print "\nEqual words = \n @equal\n";
print "\nDifferent words = \n @diff\n\n";
exit 0;

close (DICT1);
close (DICT2);

No comments:

Post a Comment