in reply to (tye)Re: line no. in a file
in thread line no. in a file

I know this has come up before on p5p, and I can only suppose that there was some reason why Ilya didn't fix it in the obvious way. You should probably check through the p5p archives to see why this hasn't already been done.

(Searching... Aha.)

Says Ilya:

Debugger is already doing local($.). This is not enough to localize $., since it is a combination of two ideas: last file handle and last line number.

References of interest:

Replies are listed 'Best First'.
(tye)Re2: line no. in a file
by tye (Sage) on Dec 29, 2000 at 20:46 UTC

    If I understand what is going on, then what we want to do is localize the "last file handle read" as well as $., but Perl gives us no access to localize the "last file handle read".

    So I think lemming's patch is okay. It seems to me that what it does is temporarilly set $. for the wrong file handle to the "right" (expected by the user) value (and the user can't tell that the line number is being reported for the wrong file, just that the "right" line number is now being reported). This is why both the @saved and local bits are required. One puts the expected value into place while the other restores the correct value for the file handle that the user isn't interested in (but that the debugger is).

    Well, I hope I got that right. I didn't dig into it so my analysis could be wrong.

            - tye (but my friends call me "Tye")

      Ok. I just looked at the perl5db.pl from 5.7 dev zip which just happens to have a perl5db.pl that's Version 1.07 as well. It's a bit different than ActiveState's version 1.07 and has a fix for $. in it. Plus a few more bits that I didn't look close enough at.