#Program: compareTwoFiles.pl #The program compares two files and output the data in File2(f2.txt) #that is not present in File1(f1.txt) into OUTFILE(ot.txt) #!/usr/bin/perl use strict; use warnings; #declaration of variables my $file1 = '/opt/programming/work/f1.txt'; my $file2 = '/opt/programming/work/f2.txt'; my $outfile = '/opt/programming/work/of.txt'; my %results = (); open FILE1, "$file1" or die "Could not open file: $! \n"; while (my $line = ){ chomp($line); $results{$line} = 1; } close (FILE1); open (OUTFILE, ">$outfile") or die "Cannot open $outfile for writing: $! \n"; open FILE2, "$file2" or die "Could not open file: $! \n"; while (my $line = ){ chomp($line); print (OUTFILE $line, "\n") unless defined($results{$line}); } close (FILE2); close (OUTFILE);