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

Re: Matching

Thread Previous
From:
Tor Hildrum
Date:
February 27, 2002 04:24
Subject:
Re: Matching
Message ID:
B8A28E9A.55C8%torhildr@mac.com
On 27/2/02 13:11, "Jon Molin" <Jon.Molin@resfeber.se> wrote:

> Iain Wallace wrote:
>> 
>> Hi,
>> 
>> 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

I'm pretty new to perl myself, but:

#!/usr/bin/perl -w
use strict;
use warnings;

my $variable1 = "line1 \n line2";
print "$1\n" if $variable1 =~ /(.+)["\n"]\sline.+/;

This is a pretty quick and dirty script that somehow does this.
It doesn't really work that nice, but I guess that would work?
It prints the first line of $variable1, if the second line of $variable one
has line in it.

-- 
T.


Thread Previous


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