I have two text files. How do I compare using perl?
-Tilu
-Tilu
use strict; use warnings; my $firstfile = 'test1.txt'; my $secondfile = 'test2.txt'; open(F1, $firstfile) or die "Unable to open $firstfile $!\n"; open(F2, $secondfile) or die "Unable to open $secondfile $!\n"; my @firstfile = <F1>; my @secondfile = <F2>; if(scalar(@firstfile) == scalar(@secondfile)) { for(my $i = 0; $i<=$#firstfile; $i++) { if($firstfile[$i] eq $secondfile[$i]) { } else { print "Difference Found in Line-".($i+1).":\n$firstfile: $firstfile[$i]\n$secondfile: $secondfile[$i]\n"; } } } else { (scalar(@firstfile)>scalar(@secondfile))?print "File $firstfile has more lines than $secondfile\n":print "File $secondfile has more lines than $firstfile\n"; } close (F1); close (F2);
Comment