有没有办法打开perl跟踪(相当于bash -x)? [英] Is there a way to turn on tracing in perl (equivalent to bash -x)?

查看:142
本文介绍了有没有办法打开perl跟踪(相当于bash -x)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在perl中有一个系统脚本。我需要一些等效的bash -x来确定脚本出了什么问题。是否有相当的东西?



编辑:什么bash -x是在评估时打印每行。这使得调试代码只是丢失一些路径变量或文件非常简单。

解决方案

看看 Devel :: Trace Devel :: ebug



鉴于此程序名为 w.pl

 #!/ usr / bin / perl 

使用strict;
使用警告;

我的$ answer = 42;

如果($ answer == 6 * 9){
打印一切运行正常。
} else {
警告某处有错误... \\\
;
}

您可以使用 Devel :: Trace 来执行执行:

  perl -d:Trace w.pl 

其中产生以下输出:

  >> w.pl:6:我的$ answer = 42; 
>> w.pl:8:if($ answer == 6 * 9){
>> w.pl:11:警告某处有一个错误... \\\
;
一定有一个bug ...


I have a system script in perl. I need some equivalent of bash -x to determine what is going wrong with the script. Is there something equivalent?

EDIT: What bash -x does is that it prints each line as it is evaluated. This makes debugging code that is just missing some path variable or file very easy.

解决方案

Take a look at Devel::Trace or Devel::ebug.

Given this program named w.pl:

#!/usr/bin/perl

use strict;
use warnings;

my $answer = 42;

if ($answer == 6 * 9) {
    print "everything is running fine.\n";
} else {
    warn "there must be a bug somewhere...\n";
}

You can use Devel::Trace to watch the execution:

perl -d:Trace w.pl

Which produces the following output:

>> w.pl:6: my $answer = 42;
>> w.pl:8: if ($answer == 6 * 9) {
>> w.pl:11:     warn "there must be a bug somewhere...\n";
there must be a bug somewhere...

这篇关于有没有办法打开perl跟踪(相当于bash -x)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆