http://qs321.pair.com?node_id=376824


in reply to Re^3: When do filehandles close?
in thread When do filehandles close?

(Thanks for the typo spotting; fixed.)

The $. behavior here is correct, if highly magical. Perl is keeping track of a property of an object that doesn't exist any more.

(Or, looking at it another way, it's not magical at all: $. is a global that gets set whenever a filehandle is accesed. Even if the handle is closed, the global remains. But there's still something DWIMmish going on, because each (active) filehandle does remember its own line number, so that when you access two files in alternation, $. knows how to keep track.

s/line number/record number/g for exactness.)