------------------------------------------------
On Mon, 10 Feb 2003 13:55:46 -0800 (PST), Jeff Westman <[EMAIL PROTECTED]> 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";  }
> 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?!
> 
> 

Arrays can not be compared in that manner. What you are comparing is the scalar 
representation of the array (aka its length) so I am assuming that the files are the 
same length. You need to compare each element of the array (and if any elements of the 
array are references, each element of that reference, etc.)

I believe this is in the FAQ, but you should probably have a look at the following:

perldoc -q "compute the difference of two arrays"
perldoc -f grep
perldoc -f map

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to