Jeff Westman wrote: > If I read 2 files into separate arrays, I *should* be able to compare > the arrays, and therefore see if the files are the same or not. SO > why doesn't this work? > > #--- begin code > #!/usr/local/bin/perl -w > > $f1 = "eghpoli1"; > $f2 = "eghpoli2"; > > open(F1, "$f1") or die "cannot open $f1: $!\n"; > open(F2, "$f2") or die "cannot open $f2: $!\n"; > > @Af1 = <F1>; > @Af2 = <F2>; > > close(F1); close(F2); > > if (@Af1 eq @Af2) { print "Files compare okay\n"; }
This just tests whether the arrays have the same number of elements. It does not test the contents. For a "brute force" approach, you could use the following test: if ("@Af1" eq "@Af2") { print "Files compare okay\n"; } This stringifies the arrays so you can compare the contents. But don't do that; read below... > else { print "Files differ\n"; } > # > #--- end code > > The files are truly different, with the last record of the file F2 > shorter than the last record of file F1. So why doesn't that work?! Are you just trying to determine if the files are identical, or do you need to know which lines are changed (a "diff" listing)? If the former, calling cmp(1) via system() is probably fastest. Or try the Perl port of cmp at <http://www.perl.com/language/ppt/src/cmp/index.html>. This will be faster than what you're doing, since it will stop reading when a difference is seen. If the latter, there's an Algorithm::Diff module on CPAN that's handy. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]