use strict;
use warnings;
my $f1 = "C:\\Documents and Settings\\KXDC7647\\Desktop\\file1.txt";
my $f2 = "C:\\Documents and Settings\\KXDC7647\\Desktop\\file2.txt";
my %results;
# CONSTRUCTING HASH ARRAY BY CONTENTS OF FILE1
# IT WILL IGNORE LINE IF IT CONTAINS WHITE SPACE AT BEGINNING
open FILE1, "$f1" or die "Could not open file: $! \n";
while (my $line = <FILE1>) {
if ($line =~ m/^\s*$/) {
next;
}
else {
$results{$line} = 1;
}
}
# CONSTRUCTING HASH ARRAY BY CONTENTS OF FILE2
open FILE2, "$f2" or die "Could not open file: $! \n";
while (my $line = <FILE2>) {
if ($line =~ m/^\s*$/) {
next;
}
else {
$results{$line}++;
}
}
close(FILE1);
close(FILE2);
# PRINTING THE DIFFERENCE IN PERL
foreach my $content (keys %results) {
print $content if values(%results) == 1;
}
foreach my $line (keys %results) {
print $line if $results{$line} == 1;
}
|