Chris E. Rempola wrote:
I'm trying to parse qmail-qread data, but don't know how to find the
number of occurrences after a particular string. Here is the data:
+++++++++++ Beginning of data +++++++++++++++++++++++++++++++++++++++++
28 Aug 2007 17:00:47 GMT #8807850 41428 <[EMAIL PROTECTED]>
done remote [EMAIL PROTECTED]
done remote [EMAIL PROTECTED]
done remote [EMAIL PROTECTED]
done remote [EMAIL PROTECTED]
done remote [EMAIL PROTECTED]
done remote [EMAIL PROTECTED]
done remote [EMAIL PROTECTED]
done remote [EMAIL PROTECTED]
done remote [EMAIL PROTECTED]
done remote [EMAIL PROTECTED]
28 Aug 2007 17:00:47 GMT #8807850 41428 <[EMAIL PROTECTED]>
done remote [EMAIL PROTECTED]
done remote [EMAIL PROTECTED]
done remote [EMAIL PROTECTED]
done remote [EMAIL PROTECTED]
done remote [EMAIL PROTECTED]
++++++++++++ End of Data ++++++++++++++++++++++++++++++++++++++
How would I make it look for the (#) sign and count every occurence of
the word(remote) below it? So the script would know that
'[EMAIL PROTECTED]' sent 10 emails and that '[EMAIL PROTECTED]' sent
5 emails. Any help appreciated. Thank you.
my ( $key, %data );
while ( <> ) {
if ( /#.*\s(\S+)/ ) {
$key = $1;
}
elsif ( /\sremote\s/ ) {
$data{ $key }++;
}
}
for my $key ( keys %data ) {
print "'$key' sent $data{$key} emails.\n";
}
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/