[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl-beginners
Subject:    Re: peek next line in file
From:       Xavier Noria <fxn () hashref ! com>
Date:       2007-09-27 8:27:07
Message-ID: 25451C53-3E07-407C-AA05-D108C3A2DD29 () hashref ! com
[Download RAW message or body]

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

> Is there a way in perl to peek 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
>
>     //?? peek next line ?? and enter conditional block//
>
>     //do some more stuff
> }

You could do this:

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

-- fxn


-- 
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic