Hi there
I have two files. For the most part they hold the same data but there are some items in one that are not in the other. I would like to pull out those items and place them in a text file for further processing.
Here is the script as I have it right now
#!/usr/local/bin/perl -w
use Exception;
use strict;
use warnings;
use English;
use FileHandle;
my $master = shift;
my $completed = shift;
open(MASTER, "$master") || die "Unable to open $master file :$!\n";
#open(COMPLETE, "$completed") || die "Unable to open $completed file :
+$!\n";
# compare the two files and then print out
# those in master file that are not in completed file
if (! $completed || ! -e $completed)
{
die new Exception("Unable to open $completed file :$!\n");
}
warn "# Reading 'COMPLETED' data";
my $hComData = getComData($completed);
warn "# Got 'COMPLETED' data: ".scalar (keys %$hComData);
# lets go though file
while(<MASTER>)
{
my @entries = split(/\n/, $_);
my $entry = $entries[0];
# lets do a test print here
#print "$entry\n";
my $h = $hComData->{$entry};
if(!$h)
{
print "$entry\n";
}
#else
#{
#print "$entry\n";
#}
}
#################################
sub getComData
{
my ($fIn) = @ARG;
my $fh = new FileHandle($fIn)
or die "";
my $hData = {};
my $check = 1;
while (my $line = $fh->getline)
{
my @cols = split(/\n/,$line);
#print "test $cols[0]\n";
my $hEntry = {
'chain' => $cols[0],
'exists' => $check++,
};
#print "$check\n";
my ($chn, $ex) = sort ($hEntry->{chain}, $hEntry->{exists});
$hData->{$chn} = $hEntry;
}
return $hData;
}
In a nutshell the script isn't working properly and I can't see quite what I'm doing wrong.
Here is a 'test' master file
1ab4A
1ao8A
1aoeA
1bjtA
1jkxA
1juvA
1mejA
1meoA
1n0uA
1obhA
1pjqA
1qzfA
and test 'completed' file
1ab4A
1aoeA
1bjtA
1obhA
1qzfA
Here the output for the program as it is at the moment
1ab4A
1ao8A
1jkxA
1juvA
1mejA
1meoA
1n0uA
1pjqA
Which is completely wrong as I need to print out all those items in the master file that are not in the completed file as well and, as you can see, thats not happening here.
All thoughts/advice much appreciated