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.


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

Given this program named


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

Which produces the following output:

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

The Devel::DumpTrace module has been available since 2011.

Sample usage:

$ cat
# a demonstration of Devel::DumpTrace
$a = 1;
$b = 3;
$c = 2 * $a + 7 * $b;
@d = ($a, $b, $c + $b);

$ perl -d:DumpTrace
>>>>>        $a:1 = 1;
>>>>>        $b:3 = 3;
>>>>>        $c:23 = 2 * $a:1 + 7 * $b:3;
>>>>>        @d:(1,3,26) = ($a:1, $b:3, $c:23 + $b:3);

You should look at "perl -d" (turn on debugger) or "perl -c" (check your script before executing

Always include these statements in your perl scripts:

use strict;
use warnings;

If you want to debug it, use the -d switch. And here are the commands:

Hope that helps.

Need Your Help

Any way to make {% extends '...' %} conditional? - Django

python ajax django django-templates

I would like to share a template between AJAX and regualr HTTP calls, the only difference is that one template needs to be served with the base.html html, the other one without.

parameter implicitly has an 'any' type

typescript visual-studio-code typescript-typings

I'm using visual studio code for a typescript project, where I use some 3rd party npm js libraries. Some of them don't provide any ts types (types.d.ts file), so whenever I use parameters or variab...