简体   繁体   中英

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

I have a Perl program written by someone else. When I run it, it silently exits without writing anything to the logfile. Is there a way I can run this Perl program step by step, line by line by the interpreter and thus get to see where it terminates?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM