in reply to Searching for variable then blank lines

If you know that dallas.txt is not going to be terribly large, then you can 'slurp' the entire file into a scalar (instead of an array) and use a regex. The trick is to use the 's' modifier to allow . to match newlines and the 'm' modifier to allow ^ to match the start of any line. See perlre for more.
my $slurped = do {local $/; <SERVER>}; # EEK! i see my mistake now! this line #my ($temp) = $slurped =~ /($arc.*)\n\n/sm; # should have been my ($temp) = $slurped =~ /^($arc.*)\n\n/sm; print OUTPUT $temp;
P.S. Use these three lines instead of declaring the array @lines and the entire foreach loop if you wish to test this suggestion. It doesn't solve your problem about understanding conditional looping, but it does provide another way to solve the problem at hand.

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)

Replies are listed 'Best First'.
Re: (jeffa) Re: Searching for variable then blank lines
by tstock (Curate) on Mar 14, 2002 at 06:14 UTC
    I think (maybe wrong) that he wants something more like:
    /($arc.*?\n)\n\n/s

    since the block ends in the first two blank lines and two empty lines are 3 line feeds.

    Tiago
      UPDATE - sorry tstock, i see what happened - i forgot to add the ^ to my example above ... most sorry :O

      Try it out: ;)

      use strict; my $arc = 'ARCSERVE.NLM'; my $slurped = do {local $/; <DATA>}; #my ($temp) = $slurped =~ /^($arc.*)\n\n/sm; my ($temp) = $slurped =~ /($arc.*?\n)\n\n/s; print $temp; __DATA__ not this one or this one asdffARCSERVE.NLM or even this one ---------------- ARCSERVE.NLM sign here and here and here and here and here ---------------- but not here blah blah blah blah blah blah
      I'm sticking to my answer (well, if i had COPIED IT CORRECTLY!!! bad jeffa!) , remember that the 's' modifier allows . to match that newline. Your suggestion would be pretty much the same (and i will admit possibly a bit safer) except you NEED 'm' and ^ in case ARCSERVE.NLM appears in the middle or end of a line.

      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)
      
        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!