I would recommend a slight rethink of the problem. There are two things (as you've explained it) that need to happen:
- We need to capture lines that aren't "THIS IS A BREAK" and process them.
- We need to know when we've hit a break line.
I would suggest that you change the logic to reflect that. Right now I don't see you ever checking at all for the break line, which is certainly not going to work.
Try it this way (pseudo-code so you can get the practice writing the Perl):
my @captured;
While I still have records:
Is this a break line?
Y - check_for_more_breaks(@captured)
@captured = ()
next item
N - save line to @captured
Anything left in @captured?
check_for_more_breaks(@captured)
sub check_for_more_breaks:
# Your actual processing here is unclear; I've taken
# a guess at it.
my @subgroup;
my $last_sequence_number;
for each line:
extract the fields
is last_sequence number defined?
N - save this one as the last sequence number
save the current data of interest in @subgroup
next
else is there a gap in the sequence numbers?
Y - summarize(@subgroup)
@subgroup = ();
save current sequence number as last
save the current data of interest
next
For
summarize(@subgroup), I don't quite get from your question what the processing you do is (record first and last in group and sum fields?). Anyway - your gap finding is missing, and you need to add logic for the two different kinds of gaps before you can summarize.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.