CS 655 Info. Delivery on the Internet - Homework 2 - Name:_______________ Assigned: Monday, September 29 Due: Friday, October 13 (Submitted by the Handin System) o Submit your codes electronically by the handin system with the submission ID hwk2. (50 points) 1. Write a Perl program to read the starting term, a, the common ratio, r, and the number of term, n of a geometric series from the command line and calculate the sum of this series. For example, your program called "geometry.pl", a possible session would look like: (10 points) > geometry.pl 2 3 6 The sum of the geometric series is 728. Hint: Use @ARGV or shift to retrieve the command-line arguments. 2. Write a Perl program to read a pattern and a file name from the command line and search a that file for the pattern. If the pattern is found, print those lines containing the pattern. A possible session would look like: (10 points) > grep.pl ate data John ate an apple. Mary had a plate of salad. where 'ate' is the pattern and 'data' is the file name. 3. Write a program that takes a text file as input and displays a count of lines and words in a file. A possible session would look like: (15 points) > wc.pl data The file contains 9 lines and 39 words. where 'data' is the file name. Hint: See word_table.pl on Page 363 4. Write a Perl program with the following specifications. (15 points) Input: A (data) file that has the following format. Programming the World Wide Web+Robert W. Sebesta+Addison Wesley+2003 Computer Networks, 4th Ed.+Andrew S. Tanenbaum+Prentice Hall+2002 : more book entries : Output: A HTML document that consists of a table with the title row Book Title, Authors, Publisher, and Year following by data rows which indicate the book title, authors, publisher, and year of each entry. A running session could be like: > booklist.pl < data > booklist.html or > booklist.pl data booklist.html The booklist.html would like like:
| Book Title | Authors | Publisher | Year |
|---|---|---|---|
| Programming the World Wide Web | Robert W. Sebesta | Addison Wesley | 2003 |
| Computer Networks, 4th Ed. | Andrew S. Tanenbaum | Prentice Hall | 2002 |