programming-examples/perl/Statement/Using while loop to calculate the number of lines in a file.pl

11 lines
215 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
$number_lines = 0;
open(FILEHANDLE, "file.txt") or die "Can not open file.txt";
while (<FILEHANDLE>) {
++$number_lines;
}
close FILEHANDLE;
print "The number of lines in file.txt = $number_lines.";