Deleting duplicate values in hash of hashes

S

sunckell

hello everyone,

Not sure how I can do this in the most efficient way. Hoping
someone will enlighten me on how I can go about doing it..

I have written a script on a sendmail 'gateway' server. (gateway for
an Exchange backend.) The script creates a report of all the
successfully transmitted emails to three particular email addresses.
Here is what I do...

First I read through the mail log file and search for all the
message id's for each of the three email addresses. Since the
information I need is not contained in one single line of the mail log,
I re-read the mail log , skipping any line that does not pertain to
what I am looking for.

The second time reading the log file I generate a hash of hashes..

$HoH{$msgid}{exchange} = The id the Exchange server assigned to the
email.
$HoH{$msgid}{year}
$HoH{$msgid}{day}
$HoH{$msgid}{time}
$HoH{$msgid}{status}

The problem I am having is that MS Exchange is sending multiple
messages, where the $HoH{$msgid}{exchange} is the same value, but the
$HoH{$msgid} value is different.

Is there a way I can remove duplicate $HoH{$msgid}{exchange} values is
the message id is different?

I thought I could see if it was defined before I populated the hash..
But I am not even getting close to the results I thought I would get..



code...


if($text =~ /^to\=</){
#check status first.
my $status = (split /stat\=/, $text)[1];
if ($status =~ /Sent\s\(/){

$HoH{$msgid}{status} = $status;
$HoH{$msgid}{date} = $date;
$HoH{$msgid}{time} = $time;
$HoH{$msgid}{year} = $year;

}else{
# we don't care about no delivered.
next;
}

#grab the email address
my($eMail) = (split /\s+/, $text)[0];

#clean up the output a little
$eMail =~ s/to\=<//;
$eMail =~ s/>,//;

$HoH{$msgid}{email} = $eMail;
}


#add exchange id to the hash.
if($text =~ /msgid\=</){
my($exchange) = (split /\s+/, $text)[4];

#clean up the output a little
$exchange =~ s/msgid\=<//;
$exchange =~ s/>,//;

## Thought I could determine if $exchange existed and not add
it.
$HoH{$msgid}{exchange} = $exchange;
next;
}



Thanks for the help...


Sincerely,
sunckell
 
M

Mumia W.

sunckell said:
hello everyone,
Hello


$HoH{$msgid}{status}
[...]
The problem I am having is that MS Exchange is sending multiple
messages, where the $HoH{$msgid}{exchange} is the same value, but the
$HoH{$msgid} value is different.

Is there a way I can remove duplicate $HoH{$msgid}{exchange} values is
the message id is different?

I thought I could see if it was defined before I populated the hash..
But I am not even getting close to the results I thought I would get..
[...]

Create a hash of exchanges and check that an item is not already in the
exchanges hash before adding it to the HoH.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top