develooper Front page | perl.beginners | Postings from February 2002

Re: Matching

Thread Previous | Thread Next
From:
John W. Krahn
Date:
February 27, 2002 05:41
Subject:
Re: Matching
Message ID:
3C7CE231.D8179BAF@acm.org
Iain Wallace wrote:
> 
> Hi,

Hello,

> I was wondering if any one can help me. Is there any
> command in perl that will let me match a line only if the next line
> fufills a certain condition, without doing a double loop over the file?
> My data is like this
> 
> Variable1 number number number
> Variable1 number number number   --- want this line
> Variable2 number number number   --- and this
> Variable2 number number number
> 
> Does any one have any ideas ?


open FILE, 'some_file' or die "Cannot open some_file: $!";

my $prev_line = <FILE>;
while ( <FILE> ) {
    if ( /certain condition/ ) {
        print "$prev_line$_";
        }
    $prev_line = $_;
    }



John
-- 
use Perl;
program
fulfillment

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About