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

I have an idea for a debugging program that might allow me to input a perl script, and it will print out the program substituting the variables with the current (at time of printing) values of each variable. It might also be cool if I set up some sort of trace function where it would actually print out the line of code (line being that seperated by ';') that is currently being utilized...and thus, it might do a couple of lines a couple of times for loops, and it would order sub routines as it needed to. I'm not too worried about writing this script for debugging of other scripts. But I'd like to do this as a subroutine for some of my programs -- so that it will actually do this to itself. My methodology for this is actually reading the perl script and executing the commands after it stores them temporarily into variables. My problem is that I'd be running this on itself, and before I attempt THAT, I think I'd like to make sure that I won't be causing any potential problems. Is there potential problems for a file reading itself to execute itself within itself? I would have a command line sub-command so that I wouldn't end up with a continuous loop.

Is there perhaps a better way to have a script output itself during execution time while also replacing variables with their actual values?


Replies are listed 'Best First'.
Re (tilly) 1: Ultimate Debugging:
by tilly (Archbishop) on Mar 09, 2001 at 08:40 UTC
    To understand recursion you must first understand recursion.

    Out of curiousity, have you played with the Perl debugger? Check out perldebug.

Re: Ultimate Debugging:
by Tyke (Pilgrim) on Mar 09, 2001 at 14:50 UTC
    If you're writing your own perl debugger you might want to look at the perldebguts document (I believe it was published from 5.6.0) which explains the debugger internals.
    -- I knock my pate and fancy wit will come Knock as I please, there's no one at home a pontiff paraphrased