General thoughts on the craft/art/science of programming and related topics.
Comments: The Interactive Debugger vs. Print Statements
Comments
Hi,
I enjoyed your article comparing the Perl interactive debugger to print statements.
Both are valuable tools, and I also prefer print statements.
My first approach to print statements was:
if ($d) { print "DEBUG sub xyz: \$myvar is $myvar\n" }
This proved to be too much typing, so I created a CPAN module to make debugging easier and quicker.
d '$myvar'
I thought you might be interested. Details are below:
The CPAN module 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.
Sample code:
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';
Produces this 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
}
Hi,
I enjoyed your article comparing the Perl interactive debugger to print statements.
Both are valuable tools, and I also prefer print statements.
My first approach to print statements was:
if ($d) { print "DEBUG sub xyz: \$myvar is $myvar\n" }
This proved to be too much typing, so I created a CPAN module to make debugging easier and quicker.
d '$myvar'
I thought you might be interested. Details are below:
The CPAN module 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.
Sample code:
Produces this output:
Many options are available to customize the output.
Full documentation can be found here: https://metacpan.org/pod/Debug::Statements
Posted by: Chris Koknat | January 6, 2015 05:12 PM