in reply to file comparison

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