in reply to line no. in a file

I suspect the problem is that:

sub save { @saved = ($@, $!, $^E, $,, $/, $\, $^W); $, = ""; $/ = "\n"; $\ = ""; $^W = 0; }
from perl5db.pl doesn't mention $. (though the real solution may be about the opposite of that -- I haven't given it enough thought).

Dive right in and patch that and see if it makes a difference. If so, I'm sure you could send your patch in as a bug using perlbug and we'd all benefit.

While your at it, patch in a option so that $^W = 0 can be $^W = 1 so you can use the debugger to interactively play with warnings. (:

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

Replies are listed 'Best First'.
Re: (tye)Re: line no. in a file
by Dominus (Parson) on Dec 29, 2000 at 11:13 UTC
    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:

      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.

Re: (tye)Re: line no. in a file
by lemming (Priest) on Dec 29, 2000 at 10:24 UTC
    tye gave me a very good hint on what to do and it was in the debugger. Version 1.07 perldb.pl from ActiveState 5.6 perl In Unix dif format:
    498c498 < $usercontext = '($@, $!, $^E, $,, $/, $\, $^W) = @saved;' . --- > $usercontext = '($@, $!, $^E, $,, $/, $\, $^W, $.) = @saved;' . 546c546 < $usercontext = '($@, $!, $^E, $,, $/, $\, $^W) = @saved;' . --- > $usercontext = '($@, $!, $^E, $,, $/, $\, $^W, $.) = @saved;' +. 1434c1434 < ($@, $!, $^E, $,, $/, $\, $^W) = @saved; --- > ($@, $!, $^E, $,, $/, $\, $^W, $.) = @saved; 1496c1496 < @saved = ($@, $!, $^E, $,, $/, $\, $^W); --- > @saved = ($@, $!, $^E, $,, $/, $\, $^W, $.); 1516a1517 > local $saved[-1]; # Preserve the old value of $.

    Can't say it's pretty, but no more ugly than before. I think I'll go check to make sure it hasn't already been fixed in a later version.

    Update:Thanks to Dominus to doing what I was going to check this morning. I was just too tired to check last night.

    More update: I would suggest getting the 1.07 version of perl5db.pl from www.perl.com 5.7.

      That is the current version of the debugger in development snapshots. So add to your version an increment in the version number, check perlvar for any other possibly useful but missing global variables, do a "diff -u" and email the result to perl5-porters@perl.org... :-)
Re: (tye)Re: line no. in a file
by Anonymous Monk on Dec 29, 2000 at 23:01 UTC
    Hi, Infact I am working on Sun Unix. I do not have any admin. previliges to modify anything. I will try with your code by saving the variables in my program and will debug. Thanks Ashok

      Just copy perl5db.pl from where @INC finds it to some directory of your own and run perl -Ithatdir -d to use your private modified debugger.

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