BillB has asked for the wisdom of the Perl Monks concerning the following question:

I have the following problem. I am running a kornshell script that setup the environment and then invokes perl by using the following code

exec ${ECU_PERL_EXEC} -x $0 $* #!perl -w -d use strict; use Net::SFTP::Foreign; use Mail::Mailer; use Getopt::Std; use File::Temp; use File::Copy; ...

My problem is that when perl starts when it finds the #!perl line it enters Perl with no problem and enters debug. It displays lines, but not the actual code on the line. If I run the script directly under Perl it displays the source. I have looked at the Perl command line options and I can't find out how to have it show the source like it will if Perl is invoked directly.

Replies are listed 'Best First'.
Re: display source lines under debug after exec (updates 2)
by LanX (Saint) on Apr 30, 2018 at 18:41 UTC
    What for?°

    IIRC does the debugger buffer the lines of the actual script into a special hash array* , you are most likely confusing the debugger about what the actual script is or what the line number is. (You didn't specify what you see)

    You could manipulate this hash array* ... but again .. why?

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Wikisyntax for the Monastery

    °) Not sure what exec ${ECU_PERL_EXEC} -x $0 $* does, but this smells like a XY problem for me

    *) perldebguts Each array @{"_<$filename"} holds the lines of $filename for a file compiled by Perl. 

    update 2

    After looking up -x in perlrun I'm pretty sure that you need to shift @{"_<$filename"} by yourself.

    But it's still a weird concept to always run a script under the debugger.

      I'm not trying to always run the script under the debugger. I want to step through the code and verify that my new Perl script is doing exactly what I want. Since it is going to be connecting to an external vendor to send files via SFTP I want to see is running correct. After The script has been debugged I will take out the -d to invoke the debugger and let it rip. I realize that I could setup my environment in a separate step but that would not be a true test of the entire script
        > I'm not trying to always run the script under the debugger

        That's the crucial point!

        A sane approach is to run the debugger manually only if needed and to avoid that hard coded switch.

        If you stick with this magic, you'll need to fix the line array by yourself.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Wikisyntax for the Monastery