Write a simple PERL script which determines the largest of five numbers.
You do a lot of comparing in your daily life. At the store you might compare the price and quality of two very similar products, for instance. Scientists also do a lot of comparing of things. One of the most basic types of scientific inquiry is to compare two groups. For instance, scientists many decades ago noticed that yellow mice tended to be more obese than white mice. To document this they took a large group of yellow mice and calulated their mean weight and did the same for a large group of white mice. This basic observation is interesting, but it begs the question: Why do the yellow mice tend to be more obese than other mice? As it turns out mice carry a gene called agouti on their second chromosome. This gene is most observably associated with coat color. There are many different forms of this gene (and many corresonding different coat colors which get expressed depending on which form of the gene an individual mouse happens to have inherited from its parents). Interestingly, one form of the gene, called viable yellow, is also associated with obesity in mice. (NOTE: Many genes influence obesity and coat color, but the agouti gene was one of the first to be associated with both obesity and coat color. Also, genes come in pairs: one inherited from the mother and the other from the father. We will discuss more about this in later units.)
Determining The Greatest of Two Values
In Perl we can perform comparisons between two values. Consider the following short script:
Adding Comments
Often programmers add comments to a script in order to help them remember what the script is for and to explain tricky parts of a program. Comments are readable by humans, but the computer ignores them. Even though this is a really simple program we will add some comments to it anyways just so you can see what comments look like. You should notice that all comments begin with a # sign. (The bang line also begins with a #, but the computer does look at this line to know what to do with the script and the bang line is always the first line of a script whereas comments can be inserted anywhere - except for the first line.)
NOTE: The construct which is used to decide which value is larger
may be slightly confusing to you.
You should think carefully about how a sequence of lines like this could be used to find the largest of several numbers. Consider three values ($a, $b, and $c). Once you have stored the larger of $a and $b in $biggest, then all you have to do is compare the values in $biggest and $c to identify the largest value from the original three values. |
ASSIGNMENT:
Write a script similar to the sample script which finds the largest of five values. You will need to use four comparison lines similar to the one shown in the sample script.