Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2023-02-02 08:23 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (16 votes). Check out past polls.