Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Tweaking the mysteries of HoHs and arrays

by McDarren (Abbot)
on Nov 19, 2007 at 10:43 UTC ( [id://651635]=note: print w/replies, xml ) Need Help??


in reply to Tweaking the mysteries of HoHs and arrays

Howdy :)

What you need to do is replace these lines:

if ( defined $messages{$id}{to} ) { $messages{$id}{to2} = $to; } else { $messages{$id}{to} = $to; }
With this:
push @{$messages{$id}{to}}, $to;
This will give you a HOHOA, and will cater for as many recipients as are found.
Run the following sample code to get an idea.
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my %messages; while (my $line = <DATA>) { if ($line =~ /relay=127\.0\.0\.1/) { my ($id, $to, $status) = (split /\s+/, $line, 10)[5,6,9]; chop($id); $to =~ s/to=<(.*?)>,/$1/; push @{$messages{$id}{to}}, $to; } } print Dumper(\%messages) and exit; __DATA__ Nov 16 10:28:51 smtp3 postfix/smtpd[17709]: connect from mailserver.ou +rdomain.gov.au[168.x.x.x] Nov 16 10:28:51 smtp3 postfix/smtpd[17709]: 66AE820809D: client=mailse +rver.ourdomain.gov.au[[168.x.x.x] Nov 16 10:28:51 smtp3 postfix/cleanup[19600]: 66AE820809D: message-id= +<56FE9AD99802CE47AF144E03064331D501F42840@mailserver.gov.au> Nov 16 10:28:51 smtp3 postfix/qmgr[9315]: 66AE820809D: from=<Terry.Pus +er@ourdomain.com>, size=11466, nrcpt=2 (queue active) Nov 16 10:28:51 smtp3 postfix/smtpd[19599]: connect from localhost.loc +aldomain[127.0.0.1] Nov 16 10:28:51 smtp3 postfix/smtpd[17709]: disconnect from mailserver +.ourdomain.gov.au[168.132.65.6] Nov 16 10:28:51 smtp3 postfix/smtpd[19599]: 883822080A4: client=localh +ost.localdomain[127.0.0.1] Nov 16 10:28:51 smtp3 postfix/cleanup[19594]: 883822080A4: message-id= +<56FE9AD99802CE47AF144E03064331D501F42840@mailserver.ourdomain.gov.au +> Nov 16 10:28:51 smtp3 postfix/qmgr[9315]: 883822080A4: from=<Terry.Pus +er@ourdomain.com>, size=11644, nrcpt=2 (queue active) Nov 16 10:28:51 smtp3 postfix/smtp[18745]: 66AE820809D: to=<carols@the +irdomain.com.au>, relay=127.0.0.1[127.0.0.1], delay=0, status=sent (2 +50 Ok: queued as 883822080A4) Nov 16 10:28:51 smtp3 postfix/smtp[18745]: 66AE820809D: to=<daleb@thei +rdomain.com.au>, relay=127.0.0.1[127.0.0.1], delay=0, status=sent (25 +0 Ok: queued as 883822080A4) Nov 16 10:28:51 smtp3 postfix/smtpd[19599]: disconnect from localhost. +localdomain[127.0.0.1] Nov 16 10:28:51 smtp3 postfix/qmgr[9315]: 66AE820809D: removed Nov 16 10:28:52 smtp3 postfix/smtp[19429]: 883822080A4: to=<carols@the +irdomain.com.au>, relay=mailhost.theirdomain.com.au[203.x.x.x], delay +=1, status=sent (250 Message queued) Nov 16 10:28:52 smtp3 postfix/smtp[19429]: 883822080A4: to=<daleb@thei +rdomain.com.au>, relay=mailhost.theirdomain.com.au[203.x.x.x], delay= +1, status=sent (250 Message queued) Nov 16 10:28:52 smtp3 postfix/qmgr[9315]: 883822080A4: removed

Hope this helps,
Darren :)

Replies are listed 'Best First'.
Re^2: Tweaking the mysteries of HoHs and arrays
by billie_t (Sexton) on Nov 19, 2007 at 22:53 UTC

    Hello again!

    Thank you - I didn't get my brackets in the right place when I tried variations along those lines. Or the array symbol outside the brackets. D'oh!

    Thank you again: it's working perfectly. :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-20 00:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found