Perl Course Practical Exam #2

crashclappergapΛογισμικό & κατασκευή λογ/κού

13 Δεκ 2013 (πριν από 3 χρόνια και 10 μήνες)

112 εμφανίσεις

Perl Course

Practical Exam #2




This exam is open everything except source code. Feel free to use whatever
manuals, books, or online resources that you wish to complete the programs.




You must write these programs yourself.




To turn in your work, print eac
h program on a separate piece of paper along with
a copy of the output generated by your program when it runs. Make sure that
your name and the problem number appear in a comment at the beginning of the
program.




I have sample data files that you can use
to test your program on the class web
page.




Good luck!!!


Program Number 1:


Write a program that takes the name of a file that contains text on the command line.
Your program should print out each word that appears in the test file, without any
punctuat
ion, on a separate line. Followed by a count of the total number of words in the
file. For the purposes of this program a word is defined as a sequence of characters
(alphabetic or otherwise) separated by white space. For example if your program was
giv
en a file that contained the following line:



“The 2nd quick brown fox, leaped over the dog and bit it’s tail.”


It would produce as output:



The


2nd


quick


brown


fox



leaped


over


the


dog


and


bit


its


tail



Words in file: 13



Program Number
2:


Modify the program you wrote in the previous question so that it prints out the number of
each word only once, prints the words in sorted order, and print out the total number of
words that were printed. Note that case does not matter (i.e. The is con
sidered to the be
the same as the). For example, if your program was given a file that contained the
following line:



“The check is in the mail. The mail is on the way.”


Your program would produce as output:



check


in


is


mail


on


the


way



Words
in file: 12


Words printed: 7




Program Number 3:


Modify the program you wrote in the previous question so that it prints out the total
number of times each word appears in the file. If your program were given the same
input as shown in the previous p
roblem, it would produce as output:



check

1


in

1


is

2


mail

2


on

1


the

4


way

1



Words in file: 12


Words printed: 7

Program Number 4:


Write a program that takes on the command line the name of a file that contains a single
DNA sequence. The se
quence may be split across several lines in the file. Your program
will produce as output the count of the number of ‘A’, ‘T’, ‘G’, and ‘C’s that appear in
the sequence. It should give the percentage of each base in the file and a count of the
total numb
er of bases. For example if your program were given a file that contained the
following sequence:



“AAAATTTTGGGGCCCCAAAAAAAA”


It will produce as output:



A

12

50%


T

4

16.667%


G

4

16.667%


C

4

16.667%



Total bases: 24