in reply to Comparing csv text file to mysql db in order to look for missing entries within the db.
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!).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparing csv text file to mysql db in order to look for missing entries within the db.
by carlo1973 (Initiate) on May 29, 2009 at 13:55 UTC |