Smallest set of commands to use Perl debugger
July 19, 2009
When you need to know whether your code is correctly run or not, using debugger is one of best choice to do that. Generally by using debug tool, you’ll be able to do these features.
- Run code line by line.
- Print contents of variable at each step.
- Step in to functions and show stack backtrace.
In perl, there is a Perl source debugger. It is easy and efficient for debugging, and provides a gdb like interfaces.
Starting the debugger up is very easy, just invoke Perl with -d option.
% perl -d test.pl
Loading DB routines from perl5db.pl version 1.28
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(test.pl:6): print "hello world\n";
DB
Basic commands are followings:
- n
- Go next line. If it’s a subroutine, execute it and get return value.
- s
- Go next line. If It’s a subroutine, step into that sub routine.
- c, c <line number | subroutine>
- Continue process towards a next breakpoint, or certain number of line, or certain sub routine.
- p <expr>
- Print expr. By this command we can see contents of variables.
- h
- Show help.
Only you learn these 5 commands, you can debug your perl script. For more detail and further learning, you can see perldebtut and perldebug.



