BIOS 546 Final Exam May 8, 2002
1. If we "use strict", what is wrong with these statements?
for ($i = 0; $i < 10; $i++) {
$var = $i + 7;
print "$var\n";
}
2. In a Perl program, $var = "ten"; and @arr = (1,3,5,9); What would the following lines print?
print $var;
print "$var";
print '$var';
print @arr;
print "@arr";
3. What is the value of $var1, $var2, and $var3 after the following commands are used?
@arr = (1,3,5,9);
$var1 = @arr;
$var2 = $#arr;
$var3 = \@arr;
3 What is printed from:
$var = 10 / 3;
print $var;
4. What is the $_ variable? Write a short piece of code using it.
5. What is the @_ variable? Write a short piece of code using it.
6. What does the statement "$abc = 7;" do? What does the statement "$abc != 7;" do?
7. @ar = ( 7, 3, 1, 24, 19, 8);
a. Write a statement to sort @ar in ASCII (alphabetical) order.
b. Write a statement to sort @ar into reverse numerical order.
8. @aa = ("Asp", "Trp", "Glu", "Lys", "Arg");
@MW = (133.10, 204.24, 147.13, 146.19, 174.20);
These two arrays represent some amino acids and their corresponding molecular weights. Write some code that sorts both arrays so the amino acids are in alphabetical order and the molecular weights are in array positions corresponding to their proper amino acids. Then write code to print them out one amino acid per line in order, with each line in the form: "amino acid : weight"
9. Using the arrays in the previous question, put the amino acids and weights into a hash, with amino acids as keys and weights as values. Print them out as above, in alphabetical order.
10. Write code to open the file aaa.txt, which is the /home/bios 546 directory, read in each line, tehn print the even-numbered lines into the file bbb.txt, in the current directory.
11. Design a statement using a regular expression that will find the sequence "GGATCC" in the string $seq, and return the 3 bases just before and the 3 bases just after this sequence.
12. Write some statements that will produce the reverse complement of the DNA sequence in $seq.
13. Write a regular expression that will match an e-mail address of the form:
any_number_of_letters_or_numbers_or_underscores@3-10letters.org_or_com_or_net
(note: I want to match .org, .com, or .net in the last part). For example: joe_blow@hotmail.com
14. What do these Unix commands do:
a. cd ..
b. pwd
c. ls -l
d. man ftp
e. more junk.txt
f. chmod 755 george
g. cp fred barney
15. What do these HTML commands do?
a. <p>
b. <hr>
c. <td>
d. <ul>
e. <title>
f. <img>
g. <h2>
16. Write the HTML code needed to make a link to www.bios.niu.edu, where the link says "Biology Dept".
17. Write the code needed to produce a form that invokes the program "/cgi-bin/test.cgi". The form should contain a text box for the user to enter a name and a "Submit" button. (Just the form part of the code--assume you have an HTML page already).
18. Write the "test.cgi" Perl program mentioned in the previous question, so that it takes the user's name and returns an HTML page that gives a greeting to that person.
19. What do the following Perl statements do?
a. substr $seq, 25, 320;
b. $sdfd{'hhh'}
c. print "\n"
d. next
e. foreach $xyz (@abc)
f. 1 .. 5
g. s/abc/xyz/
h. <HARRY>
i. die "Gurgle!"
j. chomp
k. my
l. pos
m. push
n. =~
o. system
20. What do the following SQL commands do:
a. SELECT * FROM biology;
b. INSERT INTO analysis VALUES ('a', 12);
c. UPDATE cases SET animal=hog WHERE name='fred';
d. CREATE TABLE concepts (id smallint not null autoincrement, name tinytext);
e. SELECT courses.title, courses.number, students.name FROM courses, students WHERE courses.id=students.id AND students.age > 21;
21. What do these regular patterns match:
a. /^>/
b. /\s*A/
c. /[a-c]+/
d. /\w{3,}/
e. /asdf|qwer/
f. /GACT[^AT]/
22. Write some statements that will print "Yes" if $var is less than 5, "Maybe" if $var equals 5, and "No" if $var is greater than 5.
23. Write a statement that will print out the third element for this array:
$xyz = [ 1, 7, 19, 4 ];
24. For @aoa defined below, what will each of the print statements give:
@aoa = ( [10, 20, 30], [5, 15, 25, 35], [1, 2, 3, 8] );
print "@aoa[1]";
print "$aoa[1][2]";
print "$aoa[1]";
print "@{$aoa[1]}";
25. What is stored in the @ARGV array?
26. What is STDIN?
27. Write a statement that will convert $string into an array of numbers:
$string = "1 : 3 : 5 : 7 : 9";
28. What is the difference between these three statements?
open FILE, "this.txt"
open FILE, ">this.txt"
open FILE, ">>this.txt"
29. Write a subroutine called "add" that takes 2 numbers as input and returns their sum. Also write a statement that called this subroutine and prints the result.
30. Write a subroutine called "add_ar" that takes references to 2 arrays of numbers as input and returns a reference to an array of the sums of corresponding elements. Also write a statement that called this subroutine and prints the result.
31. When using MySQL, what are the steps necessary to get information from the database (hint: how do you get a SELECT statement to work using the Perl DBI)?
32. If the database handle is $dbh, write a DBI statement that will disconnect you from the database.