Front page | perl.beginners |
Postings from February 2002
Re: Matching
Thread Previous
|
Thread Next
From:
Jon Molin
Date:
February 27, 2002 04:13
Subject:
Re: Matching
Message ID:
3C7CCCE0.B4B95CA2@resfeber.se
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
>
> Does any one have any ideas ?
if you match with //s, (treat string as single line) you can do it with
regexp (see 'perldoc perlre')
otherwise, if you have the data in an array:
my @content = <FILE>;
close (FILE);
for (my $i = 0; $i <= $#content; $i++)
{
if ($i < $#content && $content[$i] =~ /^Variable1 &&
$content[$i + 1] =~ /^Variable2/)
{
do stuff
}
}
/jon
> Thanks very much
>
> Iain
Thread Previous
|
Thread Next