Approaches to Web Development for Bioinformatics

Previous  Contents  Next
References

Perl Modules

To define a subroutine that can be reused from multiple Perl programs put the subroutine in a .pm (Perl module) file and put that file in the same directory as the program that uses the subroutine.  Alternatively, the Perl module can be placed anywhere on the Perl library search path.  To find the library search path type the command perl -V.  The library search path can be modified by setting the environment variable PERL5LIB, assuming that you are using Perl 5.  Another alternative is to use the use lib pragma to tell the Perl runtime where to look for libraries. for example


use lib qw(/home/myhome/lib);

where /home/myhome/lib is where the Perl modules are located.

Usuually, when defining a Perl module a package will be declared to prevent namespace collisions.  For example,


package MyPackage;

sub mySub {
 . . .
}

1;

The 1 at the end of the Perl module is needed for historic reasons.  The package name traditionally starts with an upper case letter.


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