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.
The program below will do what you need.
HTH,
Rob
use strict;
use warnings;
my ($sender, $count);
while (<DATA>) {
if (/#/) {
($sender) = /<(.*?)>/;
}
elsif (/done\s+remote/) {
$count++;
}
elsif ($sender) {
print "'$sender' sent $count emails\n";
$sender = $count = undef;
}
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/