For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > September 2007 > peek next line in file









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author peek next line in file
Mahurshi Akilla

2007-09-27, 3:59 am

Is there a way in perl to p the next line in the file while keeping
the line pointer the same?

I want to do something like this:

while (<INFILE> )
{

//do some stuff

//?? p next line ?? and enter conditional block//

//do some more stuff
}

Of course, there are workarounds, but it would be nice to know if this
can be done.


Mahurshi Akilla

Xavier Noria

2007-09-27, 3:59 am

On Sep 27, 2007, at 1:29 AM, Mahurshi Akilla wrote:

> Is there a way in perl to p the next line in the file while keeping
> the line pointer the same?
>
> I want to do something like this:
>
> while (<INFILE> )
> {
>
> //do some stuff
>
> //?? p next line ?? and enter conditional block//
>
> //do some more stuff
> }


You could do this:

my $pos = tell $fh;
my $next_line = <$fh>;
s $fh, $pos, 0;

-- fxn

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com