Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I need to create a perl script to read input from 2 files and parse this information into an output file. The input files are of the following form.
File1 File2 ------------------ ------------------ tableA ColumnA tableB ColumnB
How would i write a script that would read line by line from each file and write to output file. Each TableA and ColumnA value number are unique. The same goes for file2. The output file must contain exact matches of (TableA == TableB) && (ColumnA == ColumnB). If values in Files1 are not present in File2 and vice versa must display warning on same line in output file Output file must look like so.......
TableA ColumnA TableB ColumnB ??? ??? TableB ColumnB #display warning TableA ColumnA ??? ??? #display warning
Thanks in advance

Replies are listed 'Best First'.
Re: multiple file input
by CharlesClarkson (Curate) on Jul 09, 2001 at 07:41 UTC

    While not exactly the same as your question, you might consider the thread Comparing two files a great place to start.


    HTH,
    Charles K. Clarkson
Re: multiple file reading
by CharlesClarkson (Curate) on Jul 09, 2001 at 08:41 UTC

    Please don't post the same question with different titles. It's rude and it wastes the time of people who are taking the valuable time to offer free advice. I, for one, highly value thier advice and regret seeing others abuse it.



    Charles K. Clarkson
Re: multiple file reading
by voyager (Friar) on Jul 09, 2001 at 08:28 UTC
    Looks like homework. Summer school?

    Show what you've done so far and you'll get a lot more help than if you merely pose the question.

Re: multiple file reading
by wine (Scribe) on Jul 09, 2001 at 16:09 UTC
    I know this is a Perl-forum but there is a very quick way to do this with uniq.

    If the formats are exactly the same, you could use:

    cat file1 file2 | uniq -u

    to extract all lines that do not occur twice, i.e. when (tableA eq tableB && columnA eq columnB) fails.

    All lines that do occur twice can be extracted with:

    cat file1 file2 | uniq -d

    If you're files differ in format like the use of spaces or something, consider using a filter

    Note that this gives you no indication whether only the columns, or the tables or both didn't match. For that you have to user perl after all, I guess

Re: multiple file reading
by Malkavian (Friar) on Jul 09, 2001 at 18:40 UTC
    Try doing the following:
    Read each table into it's own hash, and at the same time, put an entry in the 'global' hash that contains all unique keys
    Cycle the keys for the 'global' hash, and use the 'exists' function to check for existence in hash 'a' or hash 'b'.
    Output as required, and all done.
    This does look sneakily like a homework question, so I'm not about to post any code, but hopefully this pointer helps.

    Cheers,

    Malk.