Hey there... I'm sorry you're still having trouble. I guess maybe I didn't understand exactly what it is you're trying to do?

Maybe this will help:

Add this at the top, under 'use DBI;':

use Data::Dumper;

Then before the 'DBI->connect' line add this:

print Dumper(\%data), "\n";

This will dump out all the data read in from your CSV file. You can look at this to make sure it "did something". If your CSV file is huge, copy the first 10 lines or so into another file, and use the small one for testing. Switch to the real one once all the debugging is done.

Now, I'm not clear whether you want to know if every IP in the CSV file exists in the DB, or if every IP in the DB exists in the CSV file. In my original reply, I assumed the IP in the DB was a primary key, and that you were wanting to check for the existence of other data fields indexed by that IP value. If you're trying to find IPs in the CSV that are missing from the database, that's a different problem! Instead of looping over the DB and comparing to the CSV, you should loop over the CSV and compare against the DB.

You might try changing your while loop as follows:

while ( my ($nbname, $ip) = $sth->fetchrow ) { if ($ip) { print "DB has IP=$ip for nbname=$nbname.\n"; } else { print "DB has no IP value for nbname=$nbname.\n"; if ($data{$nbname}{'IP'}) { print "... but CSV file has value: $data{$nbname}{'IP'}.\n"; } } }

The key here is that this way the loop will print something either way, every time through. That "unless($ip)" in your original code means that if there IS an $ip value, nothing will print. So maybe that's what's happening (which means no errors, right? Yay! You rock!).


In reply to Re: Comparing csv text file to mysql db in order to look for missing entries within the db. by scorpio17
in thread Comparing csv text file to mysql db in order to look for missing entries within the db. by carlo1973

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.