BIOS 546  Midterm  Exam  March 24, 2003

 

1. Write UNIX commands to accomplish the following tasks:

                a. change from the current directory to the one immediately above it.

 

                b. Move to the /home/bios546/spr03 directory

 

                c. delete the file "junk.txt"

 

                d. change the name of "trash.txt" to "junk.txt"

 

                e. View the contents of "junk.txt" one page at a time.

 

                f. change the permissions of "junk.txt" so that the owner can do anything with it, but all others can only read or execute it.

 

                g. view the names, sizes and last-modified dates (i.e. basic information about the files) of all the files in the current directory.

 

 

2. If @arr = (1, 3, 5, 7, 9), what will the following print statements produce:

                a. print @arr;

 

                b. print "@arr";

 

                c. print "$arr[2]";

 

                d. print "$arr";

 

 

3. What values are false in Perl?  What values are true?

 

 

 

4. Define the characteristics of a legal variable name in Perl.

 

 

 

 

5.  What is the result of this expression:  "cat <= dog" ?

 

 

 

6. If INFILE is the handle for a file opened for reading, write a bit of code that will read in each line, then print out the line number (use a counter to keep track of this) followed by the line itself.

 

 

 

 

 

 

 

 

 

 

 

7. What is the difference between these 3 lines:

                open FILE, "file.txt";

                open FILE, ">file.txt";

                open FILE, ">>file.txt";

 

 

 

 

 

8. On the command line a prgram is invoked with: "prog2.pl yes 45 fred".  How can you get the program to read the second argument (the "45") into the variable $num?

 

 

 

9. Write a subroutine that will read in an arbitrary number of numerical arguments and return both their sum and their product.  Be sure that any variables you create inside the subroutine are visible (scoped) only within the subroutine.  Also write a statement invoking that subroutine.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

10. Write a bit of code that goes through each element in an array of integers and prints "even" if the number is divisible by 2, "by three" if the number is divisible by 3, and "neither" if the number is not divisible by either 2 or 3.  When the number 42 is found, the program exits from the loop and print "end".

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

11. If you use the statement: "($cat, @dogs, $gerbil) = (1, 3, 5, 7, 9, 11);"  what will end up in each of the variables: $cat, @dogs, and $gerbil?

 

 

 

 

 

 

12. You have an array @arr and you ant to know how many elements it has.  Write a statement that will put the number of elements into the variable $count.

 

 

 

 

 

13. Write statements that will remove the last element from array @arr and put it on the front of that array, moving all the other elements down one position.

 

 

 

 

 

14. Write a loop that will create a hash calle "%hash", in which the numbers 1, 2, 3, 4 are the values, with their Englich names "one", "two", "three", "four" as the corresponding keys.  Then print out the key and value for all members of the hash and  delete each key-value pair right after printing it.

 

 

 

 

 

 

 

 

 

 

 

15. What is the difference between what is matched with /^cat$/ and /cat/ ?

 

 

 

16.  Write a loop that finds every instance of  "ATG" in a DNA sequence stored in the variable $seq and reports its position.

 

 

 

 

 

 

 

 

17.  Write some code that produces the reverse-complement of the DNA sequence in $seq.

 

 

 

 

 

 

18. Write a regular expression that will match a 10 digit US telephone number, which can have any of these forms: (012)345-6789, (012) 345-6789, 012-345-6789, or 0123456789 (Note the difference between the first and the second is a space following the close parenthesis).  Use the regular expression to capture the area code (the first 3 digits) in to the variable $ac, and the local number (the last 7 digits) into the variable $num.  Make sure these two variables only contain digits and no punctuation marks.

 

 

 

 

 

 

 

 

 

 

 

 

19.  Write an HTML page that has a title "Test Web Page"; a header (This is a header); a line of text; a horizontal line; a table containing 3 rows and 2 columns with the numbers 1 and 2 in the first row, 3 and 4 in the second, and 5 and 6 in the third row; an image (picture.png); and a link (www.bios.niu.edu).

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

20. Write an HTML page containing a form that invokes a  program called "word.cgi", which you must also write.  The form contains a text box that allows the user to enter a word.  The word.cgi program takes the input word as a parameter, converts it to all upper case letters, then returns it on an HTML page.  Be sure to have a Submit button on your form!