in reply to Comparing two file in Arrays
This is something I wrote a while back to compare two files line by line. It reports the line number and prints that line in both files, or prints no difference found. It might be useful to you...
#!/usr/bin/perl -w use strict; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use CGI ':standard'; my $txt1 = "/path/public_html/test/txt1.txt"; my $txt2 = "/path/public_html/test/txt2.txt"; my $count; my $item; open FH, "$txt1" or die $!; my @all = <FH>; close FH; print "Content-type: text/html\n\n"; open PAGE, "$txt2" or die $!; foreach my $line (<PAGE>) { $count++; $item = shift (@all); if ($line ne $item) { print "line no: $count<br> $line<br> $item<br>"; } else { print "No differences found<br>"; } }
|
|---|