> What is the best way to compare 2 text files for
> matching. Let's say both files have just people names
> Thanks
>
Does it matter what position they are in, or do you only want to know what
exists in both files? If it doesn't matter, you can do it as follows:
my $count = 0;
my $count2 = 0;
my $line;
my %hash;
open(FILE1, $file1) || die "Can't read $file1 : $!\n";
foreach $line (<FILE1>)
{
$count++;
chomp($line);
$hash{$line}=$count;
}
close(FILE1);
open(FILE2, $file2) || die "Can't read $file2 : $!\n";
foreach $line (<FILE2>)
{
$count2++;
chomp($line);
if ($hash{$line})
{
print "$line exists in file1.\n";
}
else
{
print "$line does NOT exist in file1.\n";
}
}
### END
if you need to know positional, then you can use the value of $hash{$line}
and compare it to $count in the second pass.
> File1 File2
> James Joe
> Tina Patrick
> Steve James
> ... ....
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs