Ken Foskey wrote:
On Fri, 2007-08-31 at 18:05 -0700, 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.
caveat emptor, untested but gives you the idea
my $line;
my $count;
while( $line = <> ) {
if( $line =~ m/#\d/ ) { # hash and a digit
$count = 0;
while( $line = <> ) {
if( $line !~ m/remote/ ) last; # exit first while loop
That is a syntax error. You need either:
if ( $line !~ m/remote/ ) { last; } # exit first while loop
Or:
last if $line !~ m/remote/; # exit first while loop
$count++;
}
print "Count $count\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/