MSc Bioinformatics Perl Programming Dr Claire Lambert Data

MSc Bioinformatics Perl Programming Dr Claire Lambert

Data Types n n n Scalars Arrays of scalars Associative arrays of scalars (hashes)

Literals n n n Never changes - fixed number string array associative array

Variables n n n Can change within the program number string array associative array

Operators n Addition u+ n Subtraction u- n or -= Multiplication u* n or += or *= Division u/ or /=

Logical operators n AND u true n AND true then true OR u false n OR false then false NOT u changes F true state becomes false F false becomes true

Relational operators n Equality u Numeric F == , != u Strings F eq n , ne Comparison u Numeric F <, <=, >, >=, <=> u Strings F lt, le, gt, ge, cmp

You should now be able to n n Setup appropriate data structures define different types and give examples illustrate operators that can be used write perl programs

Programming style n Good programming principles u correctness u efficiency u transparency, readability u modifiablity u robustness u documentation

Programming style n Importance of criteria u depends on problem u circumstances in which program is written u environment in which program is to be used n n correctness has highest priority other criteria usually equal weight

Programming style n Common mistake u start writing immediately u use stepwise refinement F top down design • top level - algorithm • bottom level - primitive statements

Programming style n Why conform to conventions? u reduce risk of errors u produce programs F readable F easy to understand F easy to debug F easy to modify or extend

Programming style n Good style rules u short statements u procedures, functions, modules u good naming of data objects u layout for readability

Programming style n Comments u under-commenting u over-commenting u main purpose F enable user • to use program • to understand program • to modify program

Programming style n Comments u what program does? u how it is run u execution time and memory requirements u limitations u special system requirements u functions and arguments u implementation information

Programming style n Efiiciency u execution time u space requirements u improvements F deeper understanding of problem F better programming u perl interpreter F execution efficiency • compilers are better at this

You should now be able to n n n n 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 n Debugging u getting rid of errors F syntax n and logical Debugger u tool to allow control when executing the program F breakpoints F print variable values

Debugging n Syntax errors u compile-time errors u error message generated n Common syntax errors u missing semi-colon u string terminator “ u errors not always on line specified u errors may not be related to message generated

Debugging n Logical errors u bugs n Perl -w filename. pl u extra warnings F unused variables (typo) F variables used before they are set n Debugger F trace, breakpoints and actions F print variable values

Debugging n Strict u forces declaration of variables u does not allow mis-referencing
![Debugging n Debugger DB<1> ua [line] ACTION u b [line] u. L u d Debugging n Debugger DB<1> ua [line] ACTION u b [line] u. L u d](http://slidetodoc.com/presentation_image_h2/aef426450953ee7aba97bf04884e8d0b/image-22.jpg)
Debugging n Debugger DB<1> ua [line] ACTION u b [line] u. L u d [line] u X variable u s and n u c [line]

You should now be able to n n n 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
- Slides: 23