next up previous
Next: About this document Up: No Title Previous: No Title

Lab Assignment #1

Due by 11:30 a.m. on Friday, January 15.

Make Perl scripts to do the following. Hand them in using the submit command.

  1. Find the longest length of a word in the on-line dictionary and print one example of a word of that length.

    The function length($s) gives the length of the string $s . Make sure you have removed any trailing newline before taking the length. For testing, you can first use the h/wds file. Note that chomp without an argument chomps $_ ; for a named string $s you can say chomp($s) It is also OK to leave off parentheses if there is no confusion: length $s

  2. Find the average of a list of numbers taken from a file with one number per line.

    Remember, variables with $ can represent numbers or strings; in this case they are numbers. Also, there is no built-in max function but you can use the $a?$b:$c operation as in C++.

    As sample data you can use the file h/scores , which contains student scores from the last math course I taught (with an extra low score thrown in).

Part of your work is to invent the needed logic, based on the Perl commands you have seen. Scripts can get input using <> .

Submit the scripts, not the results from running them. In fact, your programs should work on any appropriate data file. It doesn't matter what you name your files, since submit asks you. There is also a program checksubmit to make sure they have been submitted correctly.


Kirby A. Baker
Tue Jan 12 19:00:36 PST 1999