On Wednesday 18 July 2007 06:16, Ayesha wrote:
> Hi all
>
> I got started on Perl only today!
> I have a text file in which I need to read a line and the line after
> that. Like
>
> line1 and line2
> line2 and line3
> line3 and line4
>
> when I use while($line1 = <MYFILE>){
> $line = <MYFILE>;
> }
>
> I get output
> line1 and line2
> line3 and line4 ..etc. I guess everytime I read a line, it increases
> the counter and reads the next line. I tried playing with the $.
> variable, but it did not help.
>
> Any suggestions here will be very helpful
>
> thanks
> Ayesha
Hi Ayesha
you need to only read once per line, but remember the last one.
$prev=<MYFILE>
while ($this=<MYFILE>) {
print "$prev and $this\n";
$prev=$this;
}
Gary
--
Gary Stainburn
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/