Perl Debug
[From] http://goldenink.com/perl/perldebug.html
The concepts of the Perl debug is familiar to most programmers. Trace, breakpoint, and conditional breakpoint (watchpoint) is effective means with which to find problems in your Perl SC Ript.
Common Errors in Perl
Check for these common errors before-try to debug a program:no semi-colon at end of line. Matching pairs of delimiters: (), {}, []. Using = When you mean = =. using = = When you mean eq. using = when you mean =~. Disagreement of field, array or hash names (remember $data, $data [1], $data {1} and $Data is four different entities. Disagreement of subroutine names between execution and definition. Incorrect use of If, elsif, else. The Checking your program (and correcting the errors) using the-w switch.
Using the-w Switch
perl-w MyProgram
Both this useful command and the output from this command is frequently overlooked by experienced programmers. I has, on more than one occasion, spent an hour or 2 looking for a problem when correcting the errors displayed on The-w Switch would has corrected or led me to the correction of the problem in a couple of minutes.
The debug command
perl-d MyProgram
Essentially the-d switch allows you to communicate with the Perl executable, and allows the Perl executable to Communicat E with you.
Stepping up to the plate l-lists the next few lines p [variable name]-lets your print the value of a variable to the CO Mmand Line Q-i quit. R-returns from the subroutine If you have written your program as a few subroutines, this is the handy for running Throu GH each and checking the return. N-executes the next statement at the "This" Means you don ' t has to go through those boring subroutine calls. If you don't know what I just wrote, get to a program and try it a couple of times. You'll get the hang of it. S-the Step Command Okay, this is the key for simple debugging. Crank up your program in the debugger and step through it. If its a small program, this and the R command can take care of the most of the your needs. By the the-the-once you enter the command, just hits enter to repeat the command.
Breaking away
Breakpoints the Specify the next stopping point in a program. For example, lets say I know my problems @ line, I might insert a breakpoint on line and step through the final FIV E lines of code before the problem. You just saved hitting the ENTER key.
b -Set a breakpoint
Once you have started the Perl debugger, set a breakpoint at any executable line number.
B -sets a breakpoint at line 20.
B subroutinename -handy little deviation. If you know the subroutine name, this breaks on the first line inside the routine.
B Condition -depending on your background, which is called a conditional breakpoint or watchpoint. Perl breaks when the condition your specify is met.
Examples b x>30 Breaks at line if X is greater than b x=~/foo/i Bre AKS at line if X contains "foo" to start of the program use C (continue), which runs the program to the first breakpoint or Watchpoint.