Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: database strategy

by aufrank (Pilgrim)
on Aug 02, 2002 at 23:28 UTC ( #187249=note: print w/replies, xml ) Need Help??


in reply to database strategy

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; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://187249]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2022-12-02 10:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?