Setting breakpoints The Perl Debugger
6.6.3.5 Setting breakpoints
To figure out whats wrong, you can set a breakpoint in your code. A breakpoint is a spot in your program where you tell the debugger to stop execution so you can poke around in the code. The Perl debugger lets you set breakpoints in various ways. They let you run the program, stopping only to examine it when a statement with a breakpoint is reached. That way, you dont have to step through every line of code. If you have 5,000 lines of code, and the error happens when you hit a line of code thats first used when youre reading the 12,000th line of input, youll be happy about this feature. Notice that the part of this loop that prints out the rest of the string, once the starting two bases have been found, is the if block starting at line 40: if receivingcommittment { print; next; } Lets look at that receivingcommittment variable. Heres one way to do this. Lets set a breakpoint at line 40. Type b 40 and then c to continue, and the program proceeds until it hits line 40: DB11 b 40 DB12 c main::example6-4:40: if receivingcommittment { DB12 p C DB12 The last command, p , prints out the element from the dna array you reached in the foreach loop. Since you didnt specify a variable for the loop, it used the default _ variable. Many Perl commands such as print or pattern matching operate on the default _ variable if no other variable is given. Its the cousin of the _ default array subroutines used to hold their parameters. So the p debugger command shows that youre operating on C from the dna array, which is the first character. All well and good. But it would be good to have the program break when the variable receivingcommittment has a change in its value, and then single step from there, to see why the program isnt printing out the rest of the string. Recall that this variable is the flag whose change tells the program to print the rest of the string. First lets delete all other breakpoints: DB12 D IT-SC 129 Deleting all breakpoints... You can watch the variable with W like so: DB12 W receivingcommittment DB13 c TA Debugged program terminated. Use q to quit or R to restart, use O inhibit_exit to avoid stopping after program termination, h q, h R or h O to get additional info. DB13 Wait a minute The W command should indicate when receivingcommittment changes value. But when the program continued running with the c command, it ran to the end, meaning that receivingcommittment never changed value. So lets start up the program again and break on the line that changes its value: DB13 R Warning: some settings and command-line options may be lost Default die handler restored. Loading DB routines from perl5db.pl version 1.07 Editor support available. Enter h or h h for help, or man perldebug for more help. main::example6-4:11: my dna = CGACGTCTTCTAAGGCGA; DB13 w 45 42: next; 43 } elsif previousbase eq base1 { 44: if base2 { 45: print base1, base2; 46: recievingcommitment = 1; 47 } 48 } 49: previousbase = _; 50 } 51 DB14 b 46 DB15 c TAmain::example6-4:46: recievingcommitment = 1; DB15 n main::example6-4:49: previousbase = _; DB15 p receivingcommittment DB16 Huh? The code says its assigning the variable a value of 1, but after you execute the code, with the n and try to print out the value, it doesnt print anything. IT-SC 130 If you stare harder at the program, you see that at line 66 you misspelled receivingcommittment as recievingcommitment . That explains everything; fix it and run it again: perl example6-4 TAAGGCGA Success6.6.3.6 Fixing another bug
Parts
» OReilly.Beginning.Perl For Bioinformatics
» The Organization of Proteins
» In Silico Biology and Computer Science
» A Low and Long Learning Curve
» Ease of Programming Rapid Prototyping
» Portability, Speed, and Program Maintenance
» Perl May Already Be Installed No Internet Access?
» Downloading Binary Versus Source Code
» Unix and Linux Macintosh Windows
» Unix or Linux How to Run Perl Programs
» Text Editors Getting Started with Perl
» Finding Help Getting Started with Perl
» Saves and Backups Error Messages
» Individual Approaches to Programming Programming Strategies
» The Design Phase The Programming Process
» Algorithms The Programming Process
» Pseudocode and Code Comments
» Representing Sequence Data Sequences and Strings
» Control Flow Comments Revisited Command Interpretation
» Assignment Print Exit Statements
» Concatenating DNA Fragments Sequences and Strings
» Using the Perl Documentation
» Calculating the Reverse Complement in Perl
» Proteins, Files, and Arrays Reading Proteins in Files
» Arrays Sequences and Strings
» Scalar and List Context Exercises
» Conditional tests and matching braces
» Code Layout Motifs and Loops
» Getting User Input from the Keyboard Turning Arrays into Scalars with join
» Regular expressions and character classes
» Counting Nucleotides Motifs and Loops
» Exploding Strings into Arrays
» Operating on Strings Motifs and Loops
» Writing to Files Motifs and Loops
» Advantages of Subroutines Subroutines
» Arguments Scoping and Subroutines
» Scoping Scoping and Subroutines
» Command-Line Arguments and Arrays
» Subroutines: Pass by Value Subroutines: Pass by Reference
» Modules and Libraries of Subroutines
» use warnings; and use strict; Fixing Bugs with Comments and Print Statements
» How to start and stop the debugger Debugger command summary
» Stepping through statements with the debugger
» Setting breakpoints The Perl Debugger
» Fixing another bug use warnings; and use strict; redux
» Exercises Subroutines and Bugs
» Random Number Generators Mutations and Randomization
» Seeding the Random Number Generator Control Flow
» Making a Sentence Randomly Selecting an Element of an Array
» Formatting A Program Using Randomization
» Select a random position in a string Choose a random nucleotide
» Improving the Design Combining the Subroutines to Simulate Mutation
» Exercises Mutations and Randomization
» A Gene Expression Database Gene Expression Data Using Unsorted Arrays
» Gene Expression Data Using Sorted Arrays and Binary Search
» Gene Expression Data Using Hashes
» Translating Codons to Amino Acids
» The Redundancy of the Genetic Code
» Using Hashes for the Genetic Code
» Translating DNA into Proteins
» FASTA Format Reading DNA from Files in FASTA Format
» A Design to Read FASTA Files
» A Subroutine to Read FASTA Files
» Writing Formatted Sequence Data
» Regular Expressions Restriction Maps and Regular Expressions
» Background Planning the Program
» Restriction Enzyme Data Restriction Maps and Restriction Enzymes
» Logical Operators and the Range Operator
» Finding the Restriction Sites
» Exercises Restriction Maps and Regular Expressions
» Using Arrays Separating Sequence and Annotation
» Pattern modifiers Examples of pattern modifiers
» Separating annotations from sequence
» Using Arrays Parsing Annotations
» When to Use Regular Expressions
» Main Program Parsing Annotations
» Parsing Annotations at the Top Level
» Features Parsing the FEATURES Table
» Parsing Parsing the FEATURES Table
» DBM Essentials Indexing GenBank with DBM
» Overview of PDB Protein Data Bank
» Opening Directories Files and Folders
» Processing Many Files Files and Folders
» Extracting Primary Sequence Parsing PDB Files
» Finding Atomic Coordinates Parsing PDB Files
» The Stride Secondary Structure Predictor
» Parsing Stride Output Controlling Other Programs
» String Matching and Homology
» Extracting Annotation and Alignments
» Parsing BLAST Alignments Parsing BLAST Output
» The printf Function Presenting Data
» here Documents format and write
» Bioperl Tutorial Script Bioperl
» The Art of Program Design Web Programming
» Algorithms and Sequence Alignment Object-Oriented Programming Complex Data Structures
Show more