Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I have this code, but it doesn't work for some reason.
I basically want to loop through the data structure in $results, and remove duplicates by putting the results in a hash, then loop through that hash before entering to the database
foreach my $host_results (@$results) { foreach my $result_tab (@$host_results) { my $uniquekey = $result_tab->{'HostName'}.$result_tab->{'Qid'}; if ($relayqid_hash{$uniquekey}) { # if the relayqid exists ignore my $existing_Recipient = $relayqid_hash{$uniquekey}->{'Recipient +'}; } else { # create the hash record with the result_tab in it $relayqid_hash{$uniquekey}= $result_tab; } } foreach my $host_key (keys %relayqid_hash) { foreach my $result_tab (@$host_key) { my $subject = ($result_tab->{'Subject'}) ? $result_tab->{'Subject' +} : "[no subject]"; # do other stuff not important insert_hash($result_tab); } }
What am I doing wrong here? Any help would be great, I think i'm just looping through and referencing things wrong in the second loop.
Thanks,
Tom
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: References, hashes and arrays
by Abigail-II (Bishop) on May 27, 2004 at 09:36 UTC | |
|
Re: References, hashes and arrays
by Anonymous Monk on May 27, 2004 at 10:04 UTC | |
by Roy Johnson (Monsignor) on May 27, 2004 at 14:38 UTC |