Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
310 views
in Technique[技术] by (71.8m points)

debugging - Is there a way to turn on tracing in perl (equivalent to bash -x)?

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.

question from:https://stackoverflow.com/questions/3852395/is-there-a-way-to-turn-on-tracing-in-perl-equivalent-to-bash-x

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.
";
} else {
    warn "there must be a bug somewhere...
";
}

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...
";
there must be a bug somewhere...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...