Good day everyone!

I'm new to perl - when I say new - I mean novice to the nth extreme. If I had a towel I would put it over my head right about now so that the perl code I have been staring at for the past week couldn't hurt me any more. I do have programing experience but to be honest I haven't programed since something like 1993. Possibly even earlier than that.

I just finnished an IT course that was quite extensive although it was at a very fast pace. It lacked anything dealing with programing and only covered basic bash and batch scripting. I am now in my final week at a company for my internship, and since starting they have been getting me to work in of all things - PERL and MYSQL. Now the mysql I think I'm doing okay in but the perl I'm having more difficulty with.

The last project that I have been assigned as such is to work on a program that takes entries from a specific database, evaluates it for null or missing information and then displays it as a webpage. It also needs to compare the database to that of a csv file looking for information that may be missing from the database, again displaying the information in a webpage.

UPDATE: As discussed - the criteria has changed somewhat. no longer am I needed to evaluate for null values in the DB. I only need to compare the db to a csv file. Any entries that are in the csv but missing from the db should be reported. I've updated the code that I have here. I am not worried about displaying to a webpage yet. For now I will just be running it from the terminal for testing purposes.

Here is my code so far (Edited 05-27-09):

#!/usr/bin/perl use strict; #The Setup use warnings; use Text::CSV_XS; use DBI; my %conn_attrs = (RaiseError =>1, PrintError =>0, AutoCommit =>1); my $dbh = DBI->connect('DBI:mysql:pstsize;host=localhost'); my $sth = $dbh->prepare("SELECT DISTINCT nbname,ipaddr from sizehist o +rder by nbname "); #Read the DB into a hash array $sth->execute(); my $dbData = {}; while (my $db_ref = $sth->fetchrow_hashref ()) { $dbData->{$db_ref->{nbname}}->{$db_ref->{ipaddr}} = 0; } #Read CSV file into hash array using CSV_XS module open my $io, "<", "use_me.txt" or die "use_me.txt: $!"; my $csv = Text::CSV_XS->new ({binary => 1, eol => "\n"}); while (my $row = $csv->getline ($io)) { if ( exists($dbData->{$row->[0]}->{$row->[1]}) ) { # Mark the db rows that match. $dbData->{$row->[0]}->{$row->[1]} = 1; } } close $io; # Build output arrays. my @match = (); my @dontmatch = (); for my $nbname (sort(keys(%$dbData))) { for my $ipaddr (sort(keys(%{$dbData->{$nbname}}))) { for my $nbname (sort(keys(%{$dbData->{$ipaddr}}))) { if ( $dbData->{$nbname}->{$ipaddr} == 1 ) { push (@match, [$nbname, $ipaddr]); } else { push (@dontmatch, [$nbname, $ipaddr]); } } } } # Output: print "These db rows match:\n"; map { print "$_->[0],$_->[1]\n" } @match; print "\n"; print "These db rows don't match:\n"; map { print "$_->[0],$_->[1]\n" } @dontmatch; exit;

I really hope I can get help with this. I'm really struggling with it. I ended up purchasing two books with the hopes that I would have this done by now (MySQL Developer's Library book - fourth edition, and 5th edition of Learning Perl).

Thank you to all the Monks, guru's, genies, and higher powers for the perl world in advance. This lowely newb is unworthy but hopes to get some assistance anyways :D

Carlo


In reply to Need to compare 2 hash values 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.