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
In reply to References, hashes and arrays by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |