Ron B wrote: > My problem is how to print the next line after the line that > includes BLAH. So I want to print lines including BLAH keyword and > when BLAH is found the next line after it. > > #!/usr/bin/perl > # print lines wich include BLAH keyword > print "Content-type: text/html\n\n"; > print "<html>\n"; > print "<head>\n"; > print "<title>av</title></head><BODY>\n"; > open(HTMLOLD, "/.../.../pohja.html"); > @lines=<HTMLOLD>; > close(HTMLOLD); > $count = 0; > foreach $line (@lines) { > if ($line =~ /BLAH */) { > print "$line"; > $count++; > } > if ($count eq 50){ > last; > } > } > > print "</body>\n"; > print "</html>\n";
You could solve this by setting some kind of indicator when you find a BLAH, so the next pass through the loop would print the following line. But don't do that. Instead of reading the lines into an array, process the lines directly in a while loop like this: while (<HTMLOLD>) { if (/BLAH */) { print; # print this line $_ = <HTMLOLD>; # read following line print; # and print it } last if $. >= 50; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>