Hi
I want to compare two files which looks like this
File1: -
STRING LABEL
aabbaa A
basda B
ccdaa C
xxdas D
..
..
hgfhgfd P
asfasdf Z
File2: -
STRING LABEL
xxdas D
aabbaa A
dfsfafdf Z
fasdfas X
asfasdf Z
....
....
By picking one line from file 1 (both string and label) check for it whether it is in file 2 or not. If not found in file 2, count the total number of such strings of file 1. How do I write a script in Perl? Well, the strings are in utf8.
I've tried with the following code.
\#!/usr/bin/perl
use warnings;
use strict;
\# Sort strings properly and match all letters
use locale;
\# Read the source file as UTF-8 and set STDOUT and STDIN to UTF-8
use encoding 'utf8';
open my $FILE1, "<:encoding\(utf8\)", "$ARGV[0]" or die "Can't open file $ARGV[0]: $!";
open my $FILE2, "<:encoding\(utf8\)", "$ARGV[1]" or die "Can't write to $ARGV[1]: $!";
my %line1;
my %line2;
my $string1;
my $string2;
my $label1;
my $label2;
my $count;
while \(my $line1 = <$FILE1>\)
\{
while \(my $line2 = <$FILE2>\)
\{
while \(\($string1, $label1\) = each \(%line1\)\)
\{
while \(\($string2, $label2\) =each \(%line2\)\)
\{
if \(\($string1 ne $string2\) && \( $label1 ne $label2\)\)
\{
$count\+\+;
\}
\}
\}
\}
print $count;
}
But it's in vain. Any help is appreciated.