Approaches to Web Development for Bioinformatics

Previous  Contents  Next
References

Tools for Perl Development

Perl programmers are typically minimalists.  They most often use plain text editors, such as vi, rather than the visual integrated development environment (IDE) often used with other languages.  Learning of an IDE can be a task in itself, which may not be worth it if you are not a professional programmer or computer science student.  I use emacs30 for editing Perl programs, which is a freely available minimal development environment with the advantages of syntax coloring, basic syntax checking, and formatting, in addition to some more exotic and harder to use options.  However, emacs is a little old fashioned and has a totally different set of short cut keys that must be learned.

A debugger comes with most Perl distributions.  Invoke the debugger with a perl -d option.  For example, to debug the hello world program above


>perl -d hello.pl

Loading DB routines from perl5db.pl version 1.28
Editor support available.

Enter h or `h h' for help, or `perldoc perldebug' for more help.

main::(hello.pl:3): print "Hello World!\n";
DB<1> s
Hello World!
Debugged program terminated. Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
DB<1>

where I have put the commands to by typed in red.  Use the command s to single step through the program line by line, the command x $variable_name to print the value of a variable, and q to quit.  The specifics of debuggers vary by distribution.

Perl includes modules to assist with unit testing in the Test::More and Test::Harness modules. An example test for the object oriented code example above is


#!/usr/bin/perl -w
# A Perl program to test object oriented features

use Test::More tests=>2;
use MedicalComputing::GeneInfo;

my $geneInfo1 = MedicalComputing::GeneInfo->new( "3064", "HD", "Huntington Disease");
isa_ok($geneInfo1, 'MedicalComputing::GeneInfo');
is($geneInfo1->id(), "3064", 'The ID is 3064');

The argument to the use Test::More statement declares 2 tests.  The isa_ok function tests that the object was constructed correctly.  The is function tests that the id was returned correctly.  Obviously, more testing is needed for production code.  The output from this test script is


1..2
ok 1 - The object isa MedicalComputing::GeneInfo
ok 2 - The ID is 3064

Perl documentation is described below.  For more on Perl tools see the CPAN site.


Previous  Contents  Next
References

Contributed Comments and NotesAdd a comment.

There are no user comments.

Google

Please send ideas and opinions by email at alexamies@gmail.com.

© 2006-2007 Alex Amies