Deleting duplicate values in hash of hashes

Discussion in 'Perl Misc' started by sunckell, Jun 29, 2006.

  1. sunckell

    sunckell Guest

    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
     
    sunckell, Jun 29, 2006
    #1
    1. Advertising

  2. sunckell

    Mumia W. Guest

    sunckell wrote:
    > 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.
     
    Mumia W., Jun 29, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tore Aursand
    Replies:
    3
    Views:
    557
    Anno Siegel
    Sep 16, 2003
  2. Scott  Gilpin
    Replies:
    2
    Views:
    222
  3. Perl Learner

    Hashes of hashes or just one hash ?

    Perl Learner, Jun 8, 2005, in forum: Perl Misc
    Replies:
    11
    Views:
    218
  4. Tim O'Donovan

    Hash of hashes, of hashes, of arrays of hashes

    Tim O'Donovan, Oct 27, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    216
  5. Replies:
    3
    Views:
    209
Loading...

Share This Page