[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Matching the Next Line(s)



At 3:49 PM +0200 5/17/00, Sean Carte wrote:
>At 9:35 AM -0400 5/17/2000, Paul Schinder wrote:
>>>	$matches .= $line . '\n'; # and the next 2 lines if there are any
>>
>>Since you're not chomping the lines, this should work:
>>
>>         $matches = $line . <IN> . <IN>;
>
>Thanks Paul, that's brilliant!
>
>Is there a similarly easy way to include the previous two lines?

The easiest way would be to save the previous two lines as you go along.
If the file is small enough, just slurp the whole thing into an array

@lines = <IN>;

and work on @lines

my $i;
for ($i = 0;$i < @lines;$i++) {
	if ($lines[$i] =~ /$string)

etc.

If the file is large, just store the two previous lines somewhere.


>--
>My brain hurts!
>SeanC
>                      Mediatek Training Institute
>            129 Moore Road, Berea, Durban, South Africa
>    phone: +27 (0)31 305 4200              SeanC@mediatek.co.za
>      fax: +27 (0)31 305 4236
>                   <http://members.xoom.com/s_carte>

-- 
--
Paul Schinder
schinder@pobox.com

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org