Below is some "starter code" for you showing another method of doing this. Rather setting flags in the main body of the code, calling a subroutine to handle processing the record can be a good way. If you are in the subroutine, then that means that you are inside the record - no need to have a specific flag for that status..
100K lines isn't big enough to worry much about seeking around. I'd just save the data in a buffer and then decide what to do with it when you see the End line.
You can also look at: Flipin good, or a total flop?
I use a variety of methods for similar tasks with some attention to who I'm writing the code for and the level of Perl expertise I expect them to have. Most of the time the number of lines of code is meaningless as long as it is clear and well structured.
#### Not complete code ####
#### This is just a starting framework ###
while (my $line = <DATA>)
handle_section ($line) if $line =~ /^Start:/;
my $start_line = shift;
my ($parm) = $start_line =~ /Start:(.*)/;
push @buf, $start_line;
print "Staring Parm is: $parm\n";
while (defined ($line = <DATA>) and $line !~ /End/)
push @buf, $line;
# do something based upon End line (still in $line)
# If not an End line, then malformed record
# end of data was reached without an End line
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:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||