Creating a Reusable Perl Module

Prep readings:
- Text: Chapter 6 (pp. 98-103)
- Files:

In this assignment, we wish to:
- learn how to create and use Perl modules
- practice with code using pass by reference parameters
Getting Started with Modules
- First, read pages 102-103 of Chapter 6 on "Modules and Libraries of Subroutines."
- Next, download the first two files described above:
- vowels7.pl - This file contains the main body of a Perl program to count vowels.
The main body of a Perl program is also called the driver program. A
driver program usually does some small amount of processing, but performs
the bulk of its work by calling subroutines that exist in external files.
- MyPerlSubs.pm - This file contains reusable subroutines for various tasks.
Packages of subroutines organized into files that can be reused in other
projects are also called modules or libraries of subroutines.
Sometimes users create one large module of all their tested subroutines. Other
times it might make sense to organize the subroutines into separate files, such
as VowelCounting.pm, DNAsequencing.pm, etc.
- Look carefully at the contents of both of these files. Make sure you understand the
difference between them.
- Now, test that the driver program works correctly by running it.
- Note that these files show you the type of code packaging required
in future code you submit for this class. For any remaining labs and for Perl code
associated with your term project, you will post both your driver program and your Perl
module(s) containing your carefully documented and tested subroutines.
- In addition, future subroutines
described in your text will be available in the package posted
with the other example code from your text.
Open the BeginPerlBioinfo.pm file right now, and familiarize yourself with
its contents.
Getting More Practice with Parameter Passing
- Next, read pages 98-102 of Chapter 6 on "Passing Data to Subroutines."
- Print out the MyPerlSubs.pm subroutine module provided above and note in the code where any
subroutines are using pass by reference. Compare the syntax in the
provided code to the syntax in your book until it makes sense to you how
code performing pass
by reference is written and how it works.
- How does the call to subroutines in vowels7.pl that use pass by reference
parameters compare to calls
involving parameters to subroutines which use pass by value?
Getting Credit for Your Progress
Using the files provided above as a guide (vowels7.pl and MyPerlSubs.pm),
take your latest DNA processing code currently stored
in nucleotide-counting4.pl and reorganize it into these two files:
- nucleotide_driver1.pl - a driver program for your latest and greatest DNA processing code
- myBioSubs.pm - a module containing all the subroutines you have written so far
Next, follow these steps:
- Test your new driver program thoroughly to make sure it still works when the code is
separated into two files.
- Consider at least one subroutine that might be a good candidate for using pass by reference.
- Make any necessary changes to the subroutine in the module file and
to the call in the driver program to include pass by reference.
- Test and debug your code until everything is
still working correctly.
- Include a link to your new files on your course Webpage, near the heading,
"Lab: Creating a Reusable Perl Module."
Feel free to check out how the 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.