It starts at zero...
Quoth perlvar (emphases added): Each filehandle in Perl counts the number of lines that have been read from it. ... When a line is read from a filehandle (via "readline()" or "<>") ... $. becomes an alias to the line counter for that filehandle.
So I would say davido's assertion is not without justification: $. starts out undefined (which is very like zero) and happily becomes 1 by aliasing when the first line is read. I assume the internal filehandle line counter is 0 or undefined prior to any read on the handle. So there.
>perl -wMstrict -le "my $filename = 'text'; open my $fh, '<', $filename or die qq{opening '$filename': $!}; ;; print qq{\$. initially: }, defined $. ? qq{'$.'} : 'undefined'; ;; while (<$fh>) { chomp; print qq{$.: '$_'}; } ;; close $fh or die qq{closing '$filename': $!}; " $. initially: undefined 1: 'now is the time' 2: 'foo bar baz' 3: 'how now brown cow' 4: 'four score and seven'
In reply to Re^3: Question on Reading a file inside while and counting no.of lines
by AnomalousMonk
in thread Question on Reading a file inside while and counting no.of lines
by vyeddula
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |