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

In reply to Help With Parsing a File by PrimeLord

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.