[comp.lang.perl] a Perl bug??

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (02/05/90)

In article <2236@uvaarpa.virginia.edu> microcase!elvis!ling@nosun.west.sun.com writes:
: Is this a bug? I have seen it since perl 2.0. I beg your pardon if I
: misunderstand the use of $. and local.

: # local($_) works but not local($.).

[Script deleted.]

The $. variable antedated local() by quite some time.  And it was defined
as a read-only variable that gave the line count from the last read filehandle,
so that even if you assign it a value, when you read it, it retrieves the
value from the filehandle again.  For efficiency reasons I didn't want to
update the $. variable itself on each line read.

So when local() sets up for the value to be restored to $., it does it, but
you'll never see the value because you've changed the last read filehandle.
I don't want to change the line number in that filehandle, because the
reason we're presumably saving the value is that it belongs to another
filehandle somewhere.

So the current solution is to save the last read filehandle rather than
value of $., and restore that when the local block exits.  This has the
expected effect, and also lets you localize the last read filehandle, which
also can influence eof and tell.

Expect the fix in patch 9.  I'm not saying when to expect patch 9...  :-)

Larry