I realise that other brothers have answered most of this question but since I posted this attached to the other version of the node I felt it may be worth attaching it here (now how do I delete that other one?)

I had a similar problem with comparing files in a directory and an SQL table. The simplest approach is to load up a hash table and itterate over it.

use strict; my($f1,$f2,%ids_in_f1,%ids_in_f2); my($file,$count); $f1 = "f1_name.txt"; $f2 = "f2_name.txt"; open(F1,$f1); while(<F1>) { my(@col); chop; next if(/\+/); next if(!$_); @col = split(/\s,\s/); $ids_in_f1{$col[0]} = 1; } close(F1); open(F2,$f2); while(<F2>) { my(@col); chop; next if(/\+/); next if(!$_); # Split this file on tabs @col = split(/\t/); # This time the id is in the second column $ids_in_f2{$col[1]} = 1; if(!$ids_in_f1{$col[1]}) { print " Missing ID ".$col[1]."\n"; } } close(F2); $count = 0; print "\nThings in F1 not in F2\n"; foreach $file (sort keys(%ids_in_f1)) { next if($ids_in_f2{$file}); print " $file\n"; $count++; } print "Total things in F1 not in F2 $count\n\n";

Another thing that I often had was duplications in the SQL table, well worth checking for while reading the data.

This is a rather simplistic way to do this task but has the benefit that it is easy to modify for your needs. You also wanted to print out all the other columns, just put the values in a table and output them in a suitable way when you need to


In reply to Re: file comparison by hawtin
in thread file comparison by gasky

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.