Introduction to Bioinformatics

Practice with Hashes and Databases in Perl


Prep readings:

In this assignment, we wish to:


What You Need To Do

  1. Begin reading Chapter 8 of your text. As you encounter example code, execute the Perl programs provided.
  2. Now, carefully study the code in the hashing.pl file provided above. If something in the file doesn't make sense, use your book or on-line Perl Websites to add comments to the code so the meaning is clear to you.
  3. Next, execute this program. What type of output do you get? What is different about the various methods for displaying the information in the hash variable? What output files does this program create? Can you read these files? Why not just use the hash data type in the program, without any DBM files?
  4. Now, add a subroutine to this file called query_db. This subroutine should ask the user for a key that he/she wishes to search for in the database. The subroutine should then display the information from the database associated with that key. When developing your query_db subroutine, make sure the code handles the case where there is no matching key. If the key is not found in the database, the value returned will be undefined (stored as a value which is evaluated as false in Perl). Check for this using an if statement and display a message indicating that the key was not found. You should also set the returned value to some default text that can displayed from outside the function. Sketch out your thoughts on how to write this subroutine on paper first, then type your thoughts into the program, FIVE lines of code at a time. Be prepared for the Edit-Run-Revise (and Save) cycle each time.
  5. Now, using this file as a guide, create your own example Perl program that uses a hash variable and a DBM file. Your example must relate to your term project in some way, so give this some thought before you get started on the changes. You Perl program must have subroutines to create, display, and query the database.
  6. When you have completed the above steps and tested your program thoroughly, be sure to make these additional changes:
  7. Post your completed files on your course Web page. Choose whatever names you prefer.

Feel free to see how other students in the class are doing on the assignments.
These pages are optimized for viewing under Netscape.
© Copyright 2003. Melanie A. Sutton, Ph.D. (msutton@uwf.edu) All rights reserved.