> -----Original Message----- > From: drieux [mailto:[EMAIL PROTECTED]] > Sent: Friday, April 19, 2002 5:37 PM > To: [EMAIL PROTECTED] > Subject: Re: help parsing file > > > > On Friday, April 19, 2002, at 02:17 , Bob Showalter wrote: > [..] > >> On Friday, April 19, 2002, at 12:29 , Pedro A Reche Gallardo wrote: > >> > >>> I am trying to print only the line that contain the ">" > symbol and the > >>> next line. > > Bob, I will defer to Pedro on this - my reading had been > that given > > >line1 > line2 > line3 > > he only wanted the line1 - with the prefix symbol - and the next line > hence 'line2' - but we would not need to pick out any other lines > until we got to the next line with a 'prefix' in it... > > > drieux, your solution has contains the code (pasted from > your web page): > > > > ### while(<FH>) { > > ### if( /^$prefix/ ) { > > ### print "$_"; > > ### my $nextLine = <FH>; > > ### print "$nextLine"; > > ### } > > ### } # end while > > > > Consider the following input data: > > > >> Line 1 > >> Line 2 > > This is line 3. Should it print? > > > > Your code will not print line 3. Since it is the line > following a line > > containing a ">", it seems that it should be printed, no? > > ... > > The 'logic fault' is that I am not imposing upon '>line8' > that I pick up the line after it - since It was picked up > as the 'second line' after the match at '>line7' - but > that is either
I propose the following algorithm: my $prev; while(<>) { print if /^>/ or $prev =~ /^>/; $prev = $_; } This prints a line if it starts with > or follows a line starting with >, and is rather simple to understand. Of course, that may not be the requirement, in which case the original problem was worded vaguely. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]