How can I run through a Perl program step by step?

Yes, there is the Perl debugger which you can invoke with perl -d.

Documentation can be found in perldoc perldebug and perldoc perldebtut.

Probably the most useful commands would be:

s                 - step into current line.
n                 - step over current line.
r                 - step out of current function.
p <expr>          - print the expression.
b <line|subnm>    - sets a breakpoint
T                 - produce a stack trace.
c [<line|subnm>]  - continue running with optional one-time breakpoint.
h                 - help (for other commands).

There is a Perl module called "ptkdb" which is a standalone Perl interactive debugger. It works using the Tcl/Tk GUI, so you'll need that, too.

Depending on your OS you'll need to add some required modules.

Invoke it using

perl -d:ptkdb <your script>

If running some Unix/Linux system, you also need an X server.


Hachi has the answer. Use the Perl debugger by running perl with the -d flag. For information on how to use the debugger past starting it, see the Perl Debugging Tutorial.


There are two ways. The first is the one which Hachi and llioin already gave which is using the command-line switch "-d".

Or use an IDE. I am tried and used Komodo IDE which works like charm.

Tags:

Debugging

Perl