A program with bugs

IT-SC 121 There are situations the Perl debugger cant handle well: interacting processes that depend on timing considerations, for instance. The debugger can examine only one program at a time, and while examining, it stops the program, so timing considerations with other processes go right out the window. For most purposes, the Perl debugger is a great, essential, programming tool. This section introduces its most important features.

6.6.3.1 A program with bugs

Example 6-4 has some bugs we can examine. Its supposed to take a sequence and two bases, and output everything from those two bases to the end of the sequence if it can find them in the sequence. The two bases can be given as an argument, or if no argument is given, the program uses the bases TA by default. There is one new thing in Example 6-4 . The next statement affects the control flow in a loop. It immediately returns the control flow to the next iteration of the loop, skipping whatever else would have followed. Also, you may want to recall _ , which we discussed back in Example 5-5 in the context of a foreach loop. Example 6-4. A program with a bug or two usrbinperl A program with a bug or two An optional argument, for where to start printing the sequence, is a two-base subsequence. Print everything from the subsequence or TA if no subsequence is given as an argument to the end of the DNA. declare and initialize variables my dna = CGACGTCTTCTAAGGCGA; my dna; my receivingcommittment; my previousbase = ; mysubsequence = ; if ARGV { mysubsequence = ARGV[0]; }else{ subsequence = TA; } IT-SC 122 my base1 = substrsubsequence, 0, 1; my base2 = substrsubsequence, 1, 1; explode DNA dna = split , dna ; Pseudocode of the following loop: If youve received a committment, print the base and continue. Otherwise: If the previous base was base1, and this base is base2, print them. You have now received a committment to print the rest of the string. At each loop, save the previous base. foreach dna { if receivingcommittment { print; next; } elsif previousbase eq base1 { if base2 { print base1, base2; recievingcommitment = 1; } } previousbase = _; } print \n; exit; Heres the output of two runs of Example 6-1 : perl example 6-4 AA perl example 6-4 TA Huh? It should have printed out AAGGCGA when called with the argument AA , and TAAGGCGA when called with no arguments. There must be a bug in this program. But, if you look it over, there isnt anything obviously wrong. Its time to fire up the debugger. What follows is an actual debugging session on Example 6-4 , interspersed with comments to explain whats happening and why.

6.6.3.2 How to start and stop the debugger