Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Please help with %HoAoA

by vboy1997 (Initiate)
on May 20, 2011 at 03:11 UTC ( #905845=perlquestion: print w/ replies, xml ) Need Help??
vboy1997 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

I really did not want to ask this but i am really stuck and have no way out so desperately in need of some guidance. I'm trying to create a script that read a large file of sendmail log, store it in $HoAoA and grep the email address entered from prompt and return all the entries related to that email based on the $id. This is what i have now.

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper; <
my %HoAoA;
while ( <DATA> ) {
my @fields = split(/:,\s+/, $_, 4);
push @{ $HoAoA{$fields1} }, [ @fields0,2,3 ];
}
my @addresses;
foreach my $id ( keys %HoAoA ) {
if ( grep(/econgame\@worldgameofeconomics.com/, $HoAoA{$id}->[0]1, $HoAoA{$id}->11) ) {
push @addresses, $HoAoA{$id}->[0]1, $HoAoA{$id}->11;
}
}

__DATA__
Dec 8 08:49:21 b.mx.sonic.net sm-mta18242: jB8GnCuK018242: from=<cj@oreilly.com>, size=10731, class="0", nrcpts=2, msgid=<E4461FEB-1B74-4612-80DC-3A39B04D89B1@oreilly.com>, proto=ESMTP, daemon=MTA, relay=mwest.oreilly.com 209.204.146.24
Dec 8 08:49:21 b.mx.sonic.net sm-mta17961: jB8Gn2v5017961: lost input channel from 200216009099.user.veloxzone.com.br 200.216.9.99 to MTA after rcpt
Dec 8 08:49:21 b.mx.sonic.net sm-mta17961: jB8Gn2v5017961: from=<je-hurn@mamma.com>, size=0, class="0", nrcpts=0, proto=SMTP, daemon=MTA, relay=200216009099.user.veloxzone.com.br 200.216.9.99
Dec 8 08:49:21 d.mx.sonic.net sm-mta6438: jB8Gn1iU006438: Milter: to=<econgame@worldgameofeconomics.com>, reject=550 5.7.1 Recipient declines mail from 221.233.54.253, (DUL), see http://www.mail-abuse.com/cgi-bin/lookup?ip_address=22 1.233.54.253
Dec 8 08:49:21 c.mx.sonic.net sm-mta30845: jB8GgMPb030845: from=<Michael@MichaelRomano.net>, size=2786810, class="0", nrcpts=0, proto=ESMTP, daemon=MTA, relay=b.mail.sonic.net 64.142.19.5
Dec 8 08:49:21 b.mx.sonic.net sm-mta18528: jB8GnCuK018242: to=<mkirk@corp.sonic.net>,<dane@corp.sonic.net>, delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=160731, relay=lds.sonic.net. 208.201.249.231, dsn=2.0.0, stat=Sent (jB8GnLpC004736 Message accepted for delivery)
Dec 8 08:49:21 a.mx.sonic.net sm-mta3699: jB8Gn9Vt003699: Milter: to=<cvd@sonic.net>, reject=550 5.7.1 Recipient declines email from 80.54.242.112, <spamhaus-xbl>, Ref: http://www.spamhaus.org/query/bl?ip=80.54.242.112 Dec 8 08:49:21 a.mx.sonic.net sm-mta3699: jB8Gn9Vt003699: lost input channel from host2-112.btk.net.pl 80.54.242.112 to MTA after rcpt
Dec 8 08:49:21 a.mx.sonic.net sm-mta3699: jB8Gn9Vt003699: from=<qfqsoftmtja@hotmail.com>, size=0, class="0", nrcpts=0, proto=SMTP, daemon=MTA, relay=host2-112.btk.net.pl 80.54.242.112

It works for some emails such as cj@oreilly.com but not for all. I really don't understand why. Please help. Thank you all.

Comment on Please help with %HoAoA
Re: Please help with %HoAoA
by Tanktalus (Canon) on May 20, 2011 at 04:37 UTC

    This is your fourth question at the monastary, so welcome. However, you apparently have not paid attention to your posts, nor to any of the site documentation. This leaves it very difficult to read your code - your earlier questions involved very little code, so were much easier to mentally parse. As your questions advance, so will your code, and so will its complexity, making it harder and harder to read. Please read Markup in the Monastery and Perl Monks Approved HTML tags. Use the preview, and if it doesn't look readable, keep trying before you post. If you're having trouble, ask on the ChatterBox.

    Following these conventions will not only make it easier for us to help, but it's also easier on you. Instead of putting a <br> tag at the end of each line of code, you merely have to put in a <c> tag, paste your code after it, then put a </c> tag after the code. That's it. And then your code will be hugely more readable. Do the same around your sample data, and that will become easier to read as well.

    PS: don't forget to read How do I post a question effectively?, too.

Re: Please help with %HoAoA
by SimonClinch (Chaplain) on May 20, 2011 at 09:22 UTC
    As said, code tags are needed to make code readable. But peering through the fog, it does look like the pattern matching to get email addresses is inappropriate. The data appears to enclose email addresses in angle brackets, so having split on colon-space, additional pattern matching needs to be performed on the fields array to extract the required data from the fields.

    One world, one people

Re: Please help with %HoAoA
by John M. Dlugosz (Monsignor) on May 20, 2011 at 11:06 UTC
    Why don't you use the CPAN module, or some code like LanX gave you, as suggested by the replies to log file split into HoA? You made that earlier post, so you should have read the answers.

    And learn how to format your posts!

Re: Please help with %HoAoA
by ww (Bishop) on May 20, 2011 at 11:49 UTC
    SOPW approved, not for the question, but for the replies above.

    And approved with at least as much reluctance as vboy1997 asserts he felt in posting it, for all the reasons mentioned above.

    And please don't post unexpurgated email addresses belonging to others. Doing so makes them easy to harvest.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-09-20 17:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (160 votes), past polls