简体   繁体   English

如何逐步运行 Perl 程序?

[英]How can I run through a Perl program step by step?

I have a Perl program written by someone else.我有一个别人写的 Perl 程序。 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?有没有一种方法可以让解释器一步一步地、一行一行地运行这个 Perl 程序,从而看到它在哪里终止?

Yes, there is the Perl debugger which you can invoke with perl -d .是的,您可以使用perl -d调用 Perl 调试器。

Documentation can be found in perldoc perldebug and perldoc perldebtut .文档可以在perldoc perldebugperldoc 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.有一个名为“ptkdb”的 Perl 模块,它是一个独立的 Perl 交互式调试器。 It works using the Tcl/Tk GUI, so you'll need that, too.它使用Tcl/Tk GUI 工作,因此您也需要它。

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.如果运行一些 Unix/Linux 系统,你还需要一个 X 服务器。

Hachi has the answer.哈奇给出了答案。 Use the Perl debugger by running perl with the -d flag.通过运行带有-d标志的perl使用 Perl 调试器。 For information on how to use the debugger past starting it, see the Perl Debugging Tutorial .有关如何在启动调试器后使用它的信息,请参阅Perl 调试教程

There are two ways.有两种方法。 The first is the one which Hachi and llioin already gave which is using the command-line switch "-d".第一个是 Hachi 和 llioin 已经给出的,它使用命令行开关“-d”。

Or use an IDE .或者使用IDE I am tried and used Komodo IDE which works like charm.我尝试过并使用了Komodo IDE ,它的工作原理非常迷人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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