note: If you're using <> to iterate over @ARGV then the line numbers don't reset over the files. So on if you were reading five ten line files on line five of file three, $. will contain 25.for (<FILEHANDLE>); print "FILEHANDLE contains $. lines";
See perldoc perlvar for more info
Editor's Note:
$. is reset on an explicit close. Opening an open filehandle first does an implicit close on it, then opens it. This does NOT reset $. to zero. This is one of the many reasons to explicitly close filehandles when you are done with them. <> Uses the default filehandle and does not
explicitly close it, which is why you get the behaviour that nuance mentioned. Of course, you can also set $. yourself as a point to start counting from (although this does NOT tell the read operator to start at the specified line, $. is just a counter) and you can scope $. with local $. as well.
In reply to Re: How do I find the total number of lines in a file?
by nuance
in thread How do I find the total number of lines in a file?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |