Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

HoH, HoA, or something else?

by cajun (Chaplain)
on Oct 04, 2005 at 06:12 UTC ( [id://497135]=perlquestion: print w/replies, xml ) Need Help??

cajun has asked for the wisdom of the Perl Monks concerning the following question:

Oh wise gurus. I humbly solicit your assistance in solving this problem.

I'm parsing some mail logs to check on some mail rejections. The issue that I'm not exactly sure how to proceed with is the data that I get from the logs.

Of course each sender could be sending to multiple recipients, so a simple hash won't do the trick I don't think. I'm not sure what the best approach is. A HoH, or a HoA. What I'm hoping to end up with a report something along the lines of the following.

recipient1 sender1 sender2 sender3 ... ... recipient2 sender1 sender2 sender3 ... ...
My thoughts are a HoA is the proper way to proceed. But I want to confirm my approach is correct before proceeding. Perhaps there is a better way?

Thanks,
Mike

Update: Thanks davido. I think my needs are simple. This is a small system. Very few users, lots of senders.

Update II: Thanks wfsp. I could complicate this greatly by doing something like the following, but that is really beyond the scope of what I'm trying to do at the moment. What I'm really trying to prove is the rejects are all valid. So I will be showing this data to the powers that be and let them see if any 'valid' mail is being rejected.

recipient1 sender1 -- reject reason sender2 -- reject reason sender3 -- reject reason ... ... recipient2 sender1 -- reject reason sender2 -- reject reason sender3 -- reject reason ... ...

Replies are listed 'Best First'.
Re: HoH, HoA, or something else?
by davido (Cardinal) on Oct 04, 2005 at 06:20 UTC

    It looks like keys (recipients) paired with lists of senders. Lists are easily held in arrays. That's a hash of arrays, HoA.

    If your data retrieval needs are as simple as the data you've shown, go with the HoA.


    Dave

Re: HoH, HoA, or something else?
by wfsp (Abbot) on Oct 04, 2005 at 06:32 UTC
    Or an AoA.

    I believe any of these approaches could do what you want.

    One point to consider is whether the order of your input data is important. Your example data indicates that it could be sorted but that may not be the case with 'production' data. In this case arrays (which preserve the order) may be better than hashes (which do not).

    If you want to 'lookup' data or test for existance a hash would have an advantage.

    Perl Data Structures Cookbook

    and

    Manipulating Arrays of Arrays in Perl

    have many examples.

    Update

    Also, how would you treat duplicate data? Would each sender appear only once? With, perhaps, a count? This would also steer towards a hash.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-29 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found