Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Searching for variable then blank lines

by tstock (Curate)
on Mar 14, 2002 at 04:51 UTC ( [id://151600]=note: print w/replies, xml ) Need Help??


in reply to Searching for variable then blank lines

  1. set a true/false tag when arcserve is found
  2. write lines to file
  3. exit if two blank lines found in a row
untested:
my ($s, $b); foreach my $line (@lines) { if ($line =~ /^\n$/i) { $b++; last if (($b == 2) && $s); } else { $b = 0; } if ($line =~ /^$arc/) { $s = 'true'; } if ($s) { print OUTPUT $line; } }

Also, you can skip the array part and do
for my $line (<SERVER>) {

Tiago

Replies are listed 'Best First'.
Re: Re: Searching for variable then blank lines
by rscott212 (Sexton) on Mar 14, 2002 at 05:29 UTC
    Thanks for putting me in the right direction. I'm still confused. Will this jump down into my file, start where "arcserve.nlm" is found and print out every line, line by line, until two consecutive blank lines are found, then exit? I don't know if I was clear enough about what I was trying to do. If this is true, where should I insert this code into my scrip? Again, thanks for your help.
      yes, it does what I think you want.

      $s is true if you found the starting string, false otherwise
      $b only gets to 2 if it finds two blank lines in a row
      we only end the loop if we found two blank lines ($b) and a start ($s)
      we only print if we found a start ($s)

      (might make more sense if read from the bottom up, but then it wouldn't work correctly)

      This code works for big and small files alike, but for smaller files you can always try a regular expression if it's easier for you. If you don't use the array, this code actually has no memory problems handling very large files.

      Tiago

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://151600]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-26 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found