Are there other ways for debugging Perl programs apart from Data::Dumper and perl -d?
Debug::Statements provides an easy way to insert and enable/disable print statements for debugging.
The d() function prints the name of your variable, its value, and your subroutine name. The implementation been optimized to minimize programmer keystrokes.
Here is sample code to get you started:
my $myvar = 'some value';
my @list = ('zero', 1, 'two', "3");
my %hash = ('one' => 2, 'three' => 4);
use Debug::Statements;
my $d = 1;
d "Hello, World!";
d '$myvar';
d '@list %hash';
Output:
DEBUG sub mysub: Hello, World!
DEBUG sub mysub: $myvar = 'some value'
DEBUG sub mysub: @list = [
'zero',
1,
'two',
'3'
]
DEBUG sub mysub: %hash = {
'one' => 2,
'three' => 4
}
Many options are available to customize the output. Full documentation can be found on CPAN.