Hi rscott212. Sorry for the delay ... but you don't want to hear my problems ... ;)

Ok, i changed this line:

# match a line that only contains one new line if ($line =~ /^\n$/) {
To this:
# match a line that only contains one or more whitespace if ($line =~ /^\s+$/) {
And it worked ... there was one extra newline at the end of the extracted data, but i'll get to that in a moment. (And for the record, one of your 'blank lines' had a single space in it.)

Now, some thoughts on your thoughts. First, please learn how to indent properly. When i first glanced at your code, i really believed that the last two if blocks were OUTSIDE the foreach loop. Please, for the sanity of those trying to help, use good formatting:

foreach (@blah) { if ($foo) { # foo stuff } else { # other stuff } }
That makes all the difference in the world. Second, the integer 1 (one) makes a great true value. Instead of assigning a boolean flag the scalar value 'TRUE', just use 1 (one).

Last, you have a lot of unecessary code - here is a slight improvement for you to ponder:

# open filehandles ... my ($s, $b) = (0,0); my $arc = 'ARCSERVE.NLM'; my @lines = <DATA>; foreach my $line (@lines) { if ($line =~ /^\s+$/ and $s) { $b++; last if $b == 2; } $s = 1 if $line =~ /$arc/; print OUTPUT $line if $s and $line !~ /^\s+$/; }
This produces (using your data file) the following output:
ARCSERVE.NLM
  Version:            1
  Date:                10/22/2000
  ID:                000
  Parent ID:            x
  Type:                UNKNOWN
  Description:            ARCserve
  Flags: 
Hope this helps. :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: Exiting when parsing files by jeffa
in thread Searching for variable then blank lines by rscott212

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.