How can I run a Perl script in debugging mode (like "bash -x" for shell scripts)?
I tried the -w
parameter like the following example:
#!/usr/bin/perl -w
But it didn't work out.
How can I run a Perl script in debugging mode (like "bash -x" for shell scripts)?
I tried the -w
parameter like the following example:
#!/usr/bin/perl -w
But it didn't work out.
use strict;
use warnings;
use diagnostics;
are enough IMO.
If you want to use debugger then check out: perldebug
You can use built in command line debugger as:
perl -d yourcode.pl
Also see:
perl -Dt
is kind of like bash -x
, but you need to specifically compile perl
to allow that kind of tracing.
But with any perl
, you can run a script using the debugger:
perl -d yourscriptname yourscriptargs
See perldebtut for starters.
For bash -x
style trace of a Perl script, check out Devel::DumpTrace
. Example:
demo.pl:
#!/usr/bin/perl
# demo.pl: a demonstration of Devel::DumpTrace
$a = 1;
$b = 3;
$c = 2 * $a + 7 * $b;
@d = ($a, $b, $c + $b);
program output:
$ perl -d:DumpTrace demo.pl
>>>>> demo.pl:3: $a:1 = 1;
>>>>> demo.pl:4: $b:3 = 3;
>>>>> demo.pl:5: $c:23 = 2 * $a:1 + 7 * $b:3;
>>>>> demo.pl:6: @d:(1,3,26) = ($a:1, $b:3, $c:23 + $b:3);