Hello Monks! I know there has to be an easy solution to my problem, but I just can't seem to find it. I have a data file I am trying to parse. Here is an example of what the data may look like.
1-23-abc45 (11:01) ABC SET foo foo foo.
Foo data foo.
--
1-23-cba45 (12:02) ABC RUN foo foo foo.
Foo data foo.
--
2-34-xyz21 (12:03) ABC SET foo foo foo.
Foo data foo.
!
It's something similar to that. Now what I want to do is everytime I see ABC SET I want to look and see if two lines below it is --. If it is than I just need to ++ a variable. If not I want to just move to the next line.
I am lost on how to look two lines below once I have matched a line. Normally I would have posted the code I have tried, but I just can't come up with anything and I am sure it is simple to do. I suspect maybe Parse::RecDescent would be useful here, but I have taken a look at it and I just can't wrap my brain around how to use it. Any suggestions you might have would be very appreciated. Here is basically the code I am thinking of without the matching part.
use strict;
my $value;
open IN, "data.file" or die "$!";
while (<IN>) {
chomp;
if (/match the lines/) {
$value++;
}
}
close IN or warn "$!";
Again thanks for any suggestions.
- Prime