in reply to Exiting when parsing files
in thread Searching for variable then blank lines
Ok, i changed this line:
To this:# match a line that only contains one new line if ($line =~ /^\n$/) {
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.)# match a line that only contains one or more whitespace if ($line =~ /^\s+$/) {
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:
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).foreach (@blah) { if ($foo) { # foo stuff } else { # other stuff } }
Last, you have a lot of unecessary code - here is a slight improvement for you to ponder:
This produces (using your data file) the following output:# 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+$/; }
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)
|
|---|