The solution you really want is a database. You can get a very lightweight one via the DBD::SQLite module (you'll also want DBI if you do anything with a database).

You'll want to read your file in and store it in a database. I see that you have tab-separated files -- you probably would save yourself a lot of work by using Text::CSV_XS to parse those instead of doing it yourself.

Then, a simple query to the database will find mismatches.

Here's a general (not debugged) example:

use strict; use warnings; use DBI; use DBD::SQLite; use IO::File; use Text::CSV_XS; my $db_file = 'ref_compare.db'; my $csv = Text::CSV_XS->new({sep_char=>"\t"}); ## remove the db file if it exists unlink $db_file if -f $db_file; my $dbh = DBI->connect("dbi:SQLite:dbname=$db_file",'',''); ## create two tables. ## 1: For brd_sym_pn $dbh->do(q' CREATE TABLE brd_sym_pn ( refdes TEXT, pnum TEXT, pkgtype TEXT ) '); ## 2: For sym_text_latest $dbh->do(q' CREATE TABLE sym_text_latest ( logpnpkg TEXT, logpnum TEXT, logpkgtype TEXT ) '); ## ok, now load brd_sym_pn my $sth = $dbh->prepare(q' INSERT INTO brd_sym_pn (refdes,pnum,pkgtype) VALUES (?,?,?) '); my $brd_sym_pn_io = IO::File->new('brd_sym_pn.txt'); ## use $brd_sym_pn_io->getline to skip any "header" rows until ( $brd_sym_pn_io->eof ) { my $values = $csv->getline( $brd_sym_pn_io ); # parse data line for ( @$values ) { s/^\s+|\s+$/ } # trim lead/trail whitespace $sth->execute( @$values ); # inserts row into DB table } ## ok, now load sym_text_latest $sth = $dbh->prepare(q' INSERT INTO sym_text_latest (logpnpkg,logpnum,logpkgtype) VALUES (?,?,?) '); my $sym_text_latest = IO::File->new('sym_text_latest.txt'); ## use $sym_text_latest->getline to skip any "header" rows until ( $sym_text_latest->eof ) { my $values = $csv->getline( $sym_text_latest ); # parse data line for ( @$values ) { s/^\s+|\s+$/ } # trim lead/trail whitespace $sth->execute( @$values ); # inserts row into DB table } ## now you can use any query you want, even in other scripts ## let's find everything where pnums match, but pkgtypes don't: $sth = $dbh->prepare(q' SELECT refdes, pnum, pkgtype, logpnum, logpkgtype FROM brd_sym_pn, sym_text_latest WHERE brd_sym_pn.pnum = sym_text_latest.logpnum AND brd_sym_pn.pkgtype != sym_text_latest.logpkgtype '); $sth->execute(); # print the results out. print join "\t", qw/refdes pnum pkgtype logpnum logpkgtype/; while ( my @row = $sth->fetchrow_array ) { print join "\t", @row; }

Of course, you could also simply store your first file in a hash, using partnums as keys -- that's just lest flexible in terms of answering other questions about your data.

That should give you a fair number of ideas.

<radiant.matrix>
Ramblings and references
“A positive attitude may not solve all your problems, but it will annoy enough people to make it worth the effort.” — Herm Albright
I haven't found a problem yet that can't be solved by a well-placed trebuchet

In reply to Re: compare data between two files using Perl by radiantmatrix
in thread compare data between two files using Perl by steveb94553

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.