Lesson 9: Perl Subroutines

Prev Index Next

Required reading
Learning Perl, ed. 4:
Chapter 4; p. 54-67

or
Learning Perl, ed. 5:
Chapter 4; p. 55-67

or
Learning Perl, ed. 6:
Chapter 4; p. 63-71

Subjects covered

  • Subroutines: a subroutine is both a way of hiding complexity and a way of reusing code.
  • Scope of variables.

Necessary files to complete this exercise
To download the files to your system, just press the Shift key while you left click on the blue link. Follow the instructions.
dna7.fsa
ex5.acc


All the following exercises have to be done in Perl

  1. Make a subroutine that take a DNA sequence (string) as parameter and return the complement strand (reverse complement). Use it to improve 7.3 which works on dna7.fsa.
  2. Improve on 2.10 by making a subroutine that calculates the factorial. Add some input control (make sure you get positive integers, when you ask for a number).
  3. Make a subroutine, that returns the relevant one-letter designation for the correct ammino acid, when you give it a codon (3 bases). You can find a list here. If something invalid is given as input to the subroutine, return an error code (make one up). You can reuse the hash from last lesson for most of the exercise, if you want.
  4. Make a subroutine that (only) removes duplicates from a list and returns the clean list. Use it to improve 6.3.

This page was last updated         by Peter Wad Sackett, pws@cbs.dtu.dk