the code, as promised...
sub create_hoh { my ($dbh, $table) = @_; my (%hoh, $count); my $sth = $dbh->prepare("SELECT id, last_name, first_name, address F +ROM $table"); $sth->execute(); while (my $row_hashref = $sth->fetchrow_hashref()) { my $id = $row_hashref->{"id"}; my $key = defined $id ? $id : "unknown " . $count ++; foreach my $field (keys %$row_hashref) { my $value = $row_hashref->{$field}; $hoh{$key}{$field} = $value; } } return \%hoh; } sub compare_hashes { my ($hashref1, $hashref2) = @_; my %change_hash; foreach my $outer_key1 (sort keys %$hashref1) { foreach my $outer_key2 (sort keys %$hashref2) { if (($outer_key1 =~ /unknown/) or ($outer_key2 =~ /unknown/)) { my $last_name1 = $hashref1->{$outer_key1}{"last_name"}; my $last_name2 = $hashref2->{$outer_key2}{"last_name"}; my $first_name1 = $hashref1->{$outer_key1}{"first_name"}; my $first_name2 = $hashref2->{$outer_key2}{"first_name"}; my $address1 = $hashref1->{$outer_key1}{"address"}; my $address2 = $hashref2->{$outer_key2}{"address"}; if (($last_name1 eq $last_name2) and ($first_name1 eq $first_name2) and ($address1 eq $address2)) { foreach my $inner_key1 (sort keys %{$hashref1->{$outer_key1} +}) { foreach my $inner_key2 (sort keys %{$hashref2->{$outer_key +2}}) { if ($inner_key1 eq $inner_key2) { my $value1 = $hashref1->{$outer_key1}{$inner_key1}; my $value2 = $hashref2->{$outer_key2}{$inner_key2}; $change_hash{$outer_key1}{$inner_key1} = $value2 if (!defined $value1 and defined $value2); } } } } else { if ($outer_key1 eq $outer_key2) { foreach my $inner_key1 (sort keys %{$hashref1->{$outer_key +1}}) { foreach my $inner_key2 (sort keys %{$hashref2->{$outer_k +ey2}}) { if ($inner_key1 eq $inner_key2) { my $value1 = $hashref1->{$outer_key1}{$inner_key1}; my $value2 = $hashref2->{$outer_key2}{$inner_key2}; $change_hash{$outer_key1}{$inner_key1} = $value2 if (!defined $value1 and defined $value2); } } } } } } } } return \%change_hash; }

In reply to Re: database strategy by aufrank
in thread database strategy by aufrank

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.