On Tue, 8 Mar 2005 13:42:44 -0500, Dave Gray <[EMAIL PROTECTED]> wrote: > > This is the multi line pattern in which I wish to match: > > > > <tr> > > <td><b> String 1.2.3.4.5.6 </b></td> > > <td><img src="pics/green.gif" alt="OK"></td> > > <tr> > > One way to solve this would be to read lines from the file and save > chunks of N lines (4 in this case) in a temp variable. Then your regex > would operate on enough of the file to have a chance of working. > Something like (untested): > > my (@lines, $num) = ((), 4); > while (<INPUT>) { > push @lines, $_; > shift @lines if @lines == $num+1; > print 'lines '.($.-$num+1).' to '.($.)." match\n" > if join('',@lines) =~ /regex goes here/; > } >
That assumes that the pattern being searched for will begin 4n lines from the beginning of the file, but just because we're looking for four lines doesn't mean the file is written in four line chunks. In fact, it probably isn't. Why don't you tell us what you're actually trying to do here; I'm guessing the goal isn't to search through a file for a literal string and then print it. If you knew what you were looking for, you wouldn't need to seach the file; you could just print it. So is the ultimate goal to perform a substitution? Count the number of occurrances? What? If it's a single, reasonably sized file, try something like: my @lines = (<>); my $text = join '', @lines; $text =~ /regex/ ; If it's too big to hold in memory, things get a little more interesting. HTH, --jay -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>