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

In reply to Pulling out data from one file thats not in another by Angharad

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.