--- Ayesha <[EMAIL PROTECTED]> 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. >
Welcome to the list. Yes <> in scalar context means read a line from input. You may try this to see the $. variable. use strict; use warnings; open MYFILE,"t1.txt" or die $!; while(my $line = <MYFILE>){ print 'current line is: ' ,$line; print '$. is: ', $. , "\n"; } close MYFILE; __END__ HTH. ____________________________________________________________________________________ Luggage? GPS? Comic books? Check out fitting gifts for grads at Yahoo! Search http://search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/