Actually this will work better.  You have a double while loop.  It may
work, don't know, never done it that way.

open(FD,"$file") || die "Can not open $file";
while(<FD>) {

      print "lineNo is $. and text is $text\n";

      next if ($. < $text);
      print $line;
}

close FD;

$. is a special variable containing the current input line number of the
file being read.

Glen

Glen Lee Edwards
[EMAIL PROTECTED]

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: "[EMAIL PROTECTED]" for general perl questions
::  [EMAIL PROTECTED]
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::




>On Mon, 22 Nov 1999, gnielson wrote:
>
>>I am trying to write a perl script that will read a number from a file,
>>use that as a counter, and only print out lines above that counter number.
>>So if the number is 5 and the file is 10 lines, only the last 5 lines
>>would be printed.
>>
>>The problem is when it prints out it misses one line, so instead of
>>printing 5 lines it will print the last 4 lines. 
>>
>>Any help much appreciated.
>>
>># $text is the counter variable
>>
>>open(FD,"$file") || die "Can not open $file";
>>        while(<FD>) {
>>
>>                my $lineNo = "0";
>>                while ($line = <FD>)
>>{ 
>>                print "lineNo is $lineNo and text is $text\n";
>>
>>                next if ($lineNo < $text);
>>                print $line;
>>}
>>}
>>close FD;
>>
>>
>>
>>
>
>
>


-- 
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.

Reply via email to