in reply to Exiting when parsing files
in thread Searching for variable then blank lines

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)