3.5 Gene1: An Example of a Perl ClassThis first example of Perl code defines a very small Perl class. This code does several new things, which I will explain in detail after the code.This first version of the class is called Gene1, and it demonstrates the essential features needed to implement a simple class. Gene1 looks similar to the last module definition in Chapter 1, but with a few new wrinkles that transform it into OO software. I progress from Gene1.pm to Gene2.pm, then to Gene3.pm, and then to the final version, Gene.pm.The methods of the Gene1 class will permit creating Gene1 objects and finding out what the values of a Gene1 object's attributes are.Here's the module that implements a Gene1 class. I put the module into a file called Gene1.pm and place it into a directory on my computer that can be found when Perl needs it. I continue putting my code into my own development library directory, which on my Linux system is the directory /home/tisdall/MasteringPerlBio/development/lib. This directory is pointed out to Perl at the beginning of the testGene1 program that appears later as an example of how to use the Gene1.pm module definition. You will probably use a different directory on your computer, in which case you'll have to change this line: use lib "/home/tisdall/MasteringPerlBio/development/lib"; You can also put the directory on the command line or set the PERL5LIB environmental variable, as described in Chapter 1. Setting the PERL5LIB variable is the easiest because you don't have to change the use lib lines in the programs.A Gene1 object consists of a gene name, an organism represented by genus and species, a chromosome, and a reference to a protein structure in the PDB: package Gene1; That's the whole thing! Gene1.pm class: use strict; If I put that demonstration program code into file testGene1, I get this output from running that demonstration program with perl testGene1: Object 1: Now, let's take a look at how this Perl code works. |