in reply to not able to compare files

You have some basic program design problems here.

You are attempting to read the entire file FILE1 for each record of CONTACT. Was that you intention ?

To match "sam" with "Sam", you need to ignore case. The syntax for that would be m/^$name/i. the "i" ignores case.

Depending on how large these files are, and whether or not they are sorted, there are different approaches to solving the problem. Typically, one of the files would be read completely into memory - in this case, store the info in a hash, that you can look up quickly.

Try re-writing using these suggestions, and we can help you get through the next step.

Replies are listed 'Best First'.
Re: Re: not able to compare files
by arden (Curate) on Mar 12, 2004 at 05:46 UTC
    Ok, first off, you don't want a while loop inside of another while loop for this problem. I'd start by loading all of your people on the schedule into a hash:
    my %contacts; while (<FILE1>){ my ($person, $trash) = split(/\s/, $_, 2); $contacts{$person} = 0; }
    Next, read in your contacts and determine if they exist in your schedule:
    while (<CONTACT>){ my ($person, $extra) = split(/\s/, $_, 2); print FILE3 "$person\t$extra" unless exists $contacts{$person}; }
    Of course, if somebody appears twice in your contacts file, they'll print out twice too. While you're at it, be sure to use strict and warnings and be nice, remember to close your filehandles. You don't need to chomp() anything since you're going to want the carriage return when you print to file.

    - - arden.