SUBJECT WAS: Searching for variable then blank lines

Thanks to everyone who has helped me on this. I must be dense. :-\ Now I am getting my script to read in my file and go down to the beginning of the line starting with ARCSERVE.NLM, and it gives me *every* line after that. My script is not not exiting when it finds the first 2 returns after ARCSERVE.NLM for the first time. Below is my script and a sample of the output file.

use strict; use File::Basename; ##******** Variables ********## my $filepath = 'c:\a\netware'; my $dump = 'Netware_hw.txt'; my $arc = 'ARCSERVE.NLM'; my $serverfile = 'dallas.txt'; open (SERVER, "<$serverfile") or die "Can't open the file\n"; open (OUTPUT, ">>$filepath\\$dump"); my @lines= <SERVER>; my ($s, $b); foreach my $line (@lines) { if ($line =~ /^\n$/) { $b++; last if (($b == 2) && $s); } else { $b = 0; } if ($line =~ /$arc/) { $s = 'true'; } if ($s) { print OUTPUT $line; } } close (OUTPUT); close (SERVER); =========== OUTPUT FILE =========== ARCSERVE.NLM Version: 1 Date: 10/22/2000 ID: 000 Parent ID: x Type: UNKNOWN Description: ARCserve Flags: ASDB.NLM Version: 2 Date: 12/8/2000 ASPIBD.NLM Version: 4 Date: 12/15/2000 ID: 0
This is just an example. My file was much larger than this. I was not wanting the information starting with ASDB.NLM to the end of the file. What do I need to do to make this happen?

Thx again!


In reply to Exiting when parsing files by rscott212
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.