Perl Programming Dr Claire Lambert MSc Bioinformatics Perl Programming Dr Claire Lambert
Data Types Scalars Arrays of scalars Associative arrays of scalars (hashes)
Literals Never changes - fixed number string array associative array
Variables Can change within the program number string array associative array
Operators Addition Subtraction Multiplication Division + or += - or -=
Logical operators AND OR NOT true AND true then true false OR false then false NOT changes state true becomes false false becomes true
Relational operators Equality Comparison Numeric Strings == , != eq , ne Comparison <, <=, >, >=, <=> lt, le, gt, ge, cmp
You should now be able to Setup appropriate data structures define different types and give examples illustrate operators that can be used write perl programs
Programming style Good programming principles correctness efficiency transparency, readability modifiablity robustness documentation
Programming style Importance of criteria depends on problem circumstances in which program is written environment in which program is to be used correctness has highest priority other criteria usually equal weight
Programming style Common mistake start writing immediately use stepwise refinement top down design top level - algorithm bottom level - primitive statements
Programming style Why conform to conventions? reduce risk of errors produce programs readable easy to understand easy to debug easy to modify or extend
Programming style Good style rules short statements procedures, functions, modules good naming of data objects layout for readability
Programming style Comments under-commenting over-commenting main purpose enable user to use program to understand program to modify program
Programming style Comments what program does? how it is run execution time and memory requirements limitations special system requirements functions and arguments implementation information
Programming style Efiiciency execution time space requirements improvements deeper understanding of problem better programming perl interpreter execution efficiency compilers are better at this
You should now be able to Describe good programming principles (criteria) the importance of the criteria identify common mistakes made explain why conform to style identify good rules of style why use comments, examples identify areas of efficiency
Debugging Debugging Debugger getting rid of errors syntax and logical Debugger tool to allow control when executing the program breakpoints print variable values
Debugging Syntax errors Common syntax errors compile-time errors error message generated Common syntax errors missing semi-colon string terminator “ errors not always on line specified errors may not be related to message generated
Debugging Logical errors Perl -w filename.pl Debugger bugs extra warnings unused variables (typo) variables used before they are set Debugger trace, breakpoints and actions print variable values
Debugging Strict forces declaration of variables does not allow mis-referencing
Debugging Debugger DB<1> a [line] ACTION b [line] L d [line] X variable s and n c [line]
You should now be able to Define what debugging is identify types of errors and common errors explain command line option -w use strict to force variable declaration use a debugger for a perl program