First, I would ask, how many lines in each file ? under 100 ? above 10000 ?
because that effect to choose the tatic for making things done.

Well, I assume there is reasonable to carry 10000 names and each name not
longer then 20 character.... ( consumed about 200KB, still acceptable )....
and I will do so :

use strict;
my (@names, @matches) ;

# Reading and record names into @names
open my $A, "FileA";
while (my $line = <$A>)
{ my ($name, $waste ) = split /,/, $line, 2;
    push (@names, $name)
}close $A;

# Find matching name in B and record them into @matches
open my $B, "FileB";
while (my $line = <$B>)
{ my ($name, $waste )  = split /,/, $line, 2;
    push (@matches, $name ) if ( grep /$name/, @names )
} close $B;

# Print results
print "$_<br>\n" for (@matches);
# Omit <br> if the printout is not returned as HTML format;

Remarks :
1. Code not been tested.
2. I suppose your line format is exactly same as you provided.

HTH






----- Original Message ----- 
From: "Cynthia Xun Liu" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 22, 2003 11:15 PM
Subject: Comparing two files


> Hi,
>
> Could anybody help me with the code of comparing files? I have two files
> :
> File A: name, info1, info2...
> FileB: name, info1, info2...
> I want to print out all the lines in File A with the same names as in
> File B.
> Thanks.
>
>
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



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

Reply via email to