Perl Tutorial

 

Table of Contents

Debugging the Program

In this step we'll add breakpoints to the program and "debug" it. That is, we'll run the program in chunks, so that we can watch variables and view output as it is generated.

  1. Set a breakpoint On the "parse.pl" tab, click on the grey margin to the left of line 9 of the program. This will set a breakpoint, indicated by a green circle.
  2. Run the debugger Select Debug|Start (or <F5>, or use the Debug Toolbar buttons). In the Debugging Options dialog, click OK to accept the defaults. The debugger will process the program until it encounters the first breakpoint.

Komodo Tip Debugger commands can be accessed from the Debug menu, by shortcut keys, or from the Debug Toolbar. For a summary of debugger commands, see Debugger Command List.

  1. Watch the debug process Notice that the breakpoint turns red, which indicates that the debugger is running. A yellow arrow on the breakpoint indicates the position at which the debugger has halted. Click on the "mailexport.xml" tab; notice that the file's contents have been cleared (and notice that Komodo senses that the file has changed on disk, and prompts you to refresh the version in the Editor).
  2. View variables On the Output Pane, click the Variables tab. On the Proximity tab, the input and output files have been assigned values; the Registers tab shows reserved Perl processing registers.
  3. Step Into Select Debug|Step Into. "Step Into" is a debugger command that causes the debugger to execute the current line and then stop at the next processing line (notice that the lines between 7 and 16 are not Perl statements).
  4. Step Into again On line 16, the processing transfers to the module Text::CSV_XS. Komodo opens the file CSV_XS.pm and stops the debugger at the active line in the module.
  5. Step Out Select Debug|Step Out. The Step Out command will make the debugger execute the function in Text::CSV_XS and pause at the next line of processing, which is back in parse.pl on line 19.
  6. Step Over Select Debug|Step Over. The debugger will process the function in line 19 without opening the module containing the "getline" function.

Komodo Tip What do the debugger commands do?

  • Step In executes the current line of code and pauses at the following line.
  • Step Over executes the current line of code. If the line of code calls a function or method, the function or method is executed in the background and the debugger pauses at the line that follows the original line.
  • Step Out when the debugger is within a function or method, Step Out will execute the code without stepping through the code line by line. The debugger will stop on the line of code following the function or method call in the calling program.
  1. Set Another Breakpoint Click on the grey margin to the left of line 21 to set another breakpoint.
  2. Step Out It appears that nothing happened. However, the debugger actually completed one iteration of the "while loop" (from lines 21 to 51). To see how this works, set another breakpoint at line 37, and Step Out again. The debugger will stop at line 37. On the Variables tab of the Output pane, look at the data assigned the $record variable. Then Step Out, and notice that $record is no longer displayed, and the debugger is back on line 21. Step Out again, and look at the $record variable - it now contains data from the next record in the input file.
  3. Stop the Debugger Select Debug|Stop to stop the Komodo Debugger.

Perl Pointer Did you notice that output wasn't written to mailexport.xml after every iteration of the while loop? This is because Perl maintains an internal buffer for writing to files. You can set the buffer to "autoflush" using the special Perl variable "$|".


Top Previous Next