CS205 Fall 2004 Midterm Exam

Instructions: Answer all questions on the form below by selecting the best answer, or filling in the answer where required.

You must press the "Submit Exam" button at the bottom of the form for your exam to be submitted for grading. Please do not leave or refresh this page from your browser window. Instead, start a new browser window if needed. Some people have accidentally lost some answers by leaving this browser window.

This exam has 20 questions. Before starting, scroll to the bottom to make sure you have the whole exam (CNTL-RELOAD if not).

To protect against possible problems (like a computer failure), you might want to WRITE your responses on a separate sheet of paper. You don't need to turn in the sheet of paper - it's just for your protection in case something goes wrong.


Please type your preferred email address (for grades):

During this exam you:

Please write your name to pledge your understanding of these guidelines, and conformance to other UAF guidelines for intellectual integrity (this is required for your exam to be graded):


Multiple choice questions. 15 questions, 1 point each.

  1. Today, Perl doesn't really stand for anything. But in the past, what was one acronym used for Perl?
    1. Practical Extraction and Reporting Language
    2. Practically Everything you Really Need
    3. Pretty Evolutionary Real-time Language
    4. None of the above
    5. All of the above

  2. Which is a difference between a scalar and a list?
    1. Scalars are accessed by their element subscript
    2. All arrays are lists
    3. All lists are arrays
    4. A and C above
    5. All of the above

  3. Who is a main originator of Perl?
    1. Theo de Raadt
    2. Linux Torvalds
    3. Larry Wall
    4. All of the above
    5. None of the above

  4. True or false: Perl is available for Linux, but not Unix.
    1. True
    2. False

  5. Which is true about associative arrays?
    1. They may not use numbers as subscripts
    2. There is no way to count the number of elements in associative arrays
    3. Only non-linear non-extensible hash algorithms may be used
    4. All of the above
    5. None of the above

  6. What may the "pod2text" program be used for?
    1. To display the GNU License
    2. To encapsulate (or enPOD) Perl bytecode for later compilation
    3. To convert POD data to formatted ASCII text
    4. All of the above
    5. None of the above

  7. What is the difference in execution of these two statements:
    print "hello" . " " . "world." . "\n";
    print 'hello' . ' ' . 'world.' . '\n';

    1. The first statement interprets the embedded line feed character
    2. The second statement interprets the embedded line feed character
    3. The second statement is the favored syntax
    4. All of the above
    5. None of the above

  8. Which statement is true?
    1. while loops are the same as GOTO switches
    2. until loops always execute at least once
    3. foreach can only iterate over $_
    4. All of the above
    5. None of the above

  9. Why use my?
    1. To specify the scope of a variable
    2. To specify the maximum array size
    3. To specify the minimum Perl version
    4. All of the above
    5. None of the above

  10. For making your Perl programs more portable, which of the following is the least likely to be fully compatible between Linux and Windows systems?
    1. Loop syntax
    2. Variable scoping
    3. External files
    4. All of the above
    5. None of the above

  11. Just because sorting is easy in Perl, doesn't mean it's ____________
    1. Computationally inefficient
    2. Computationally inexpensive
    3. Infrequently used
    4. All of the above
    5. None of the above

  12. How are return values from "chomp" different than from "split"?
    1. The return value of chomp is the modified input
    2. The return value of split is the modified input
    3. chomp only operates in LIST context
    4. All of the above
    5. None of the above

  13. What would you probably first do before using Perl's "seek" function?
    1. Get a file handle with "open"
    2. Get a directory handle with "opendir"
    3. Get file information with "stat"
    4. All of the above
    5. None of the above

  14. Which is incorrect syntax?
    1. $a[$b] = "hello";
    2. $a["b"] = "hello";
    3. $a{b} = "hello";
    4. All of the above are incorrect
    5. None of the above are incorrect

  15. Which is true about compiling and running Perl programs?
    1. Perl is always faster than Java, because Perl never needs to be compiled
    2. Perl is always faster than C or C++, because it is largeley platform-independent
    3. Perl is always faster than compiled languages, because Perl prevents programmers from programming error (bugs)
    4. All of the above
    5. None of the above

  16. Programming exercise (15 points): "mail merge." Create a file with three names, one per line:
    Dudley Duck
    Peter Panda
    Thomas Crane

    Write a Perl program to open and read the names from the file, then output three new files with the skeleton of a form letter using each line's full name (first and last) in the address, but just their first in the salutation.

    Required input: the file mentioned above

    Required output: One file per input name. The file should be named with the firstname and lastname, but in lower case with no spaces, with .txt at the end (i.e., "Dudley Duck" would become "dudleyduck.txt"). Each file should have four lines, of this form (use the same address for each):


    Mr. Dudley Duck
    106 Chapman Hall
    
    Dear Dudley:

    Additional requirement: Use a loop to read & act on the input lines, so that the program would function correctly for other 2-part names.

    EITHER paste your program in the box provided, OR email it to Prof. Newby (newby AT arsc.edu). You do not need to submit a sample run, just the program. Points are awarded based on functionality, parsimony and legibility. Don't forget to Submit the rest of your exam, below.



This is the end of the exam. For the exam to be graded, first check your work above, then click the button below: