Your first "while" statement is completely superflouos and is the cause of
your problem. You think your line number is 0 when you've actually read two
lines. You also need an increment statement for $lineNo.
hth
nate
-----Original Message-----
From: gnielson [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 22, 1999 8:34 AM
To: Redhat list
Subject: Help with perl next if loop problem
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.
--
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.