Документация
HTML CSS PHP PERL другое

Section 8.6.  Exercises

 
Previous
Table of Contents
Next

8.6. Exercises

You can find the answers to these exercises in "Answers for Chapter 8" in the Appendix.

8.6.1. Exercise 1 [20 min]

Write a program that prints the date and the day of the week, but allow the user to choose to send the output either to a file, a scalar, or both at the same time. No matter which output channels the user selects, send the output with a single print statement. If the user chooses to send the output to a scalar, at the end of the program print the scalar's value to standard output.

8.6.2. Exercise 2 [30 min]

The Professor has to read a logfile that looks like:

Gilligan: 1 coconut
Skipper: 3 coconuts
Gilligan: 1 banana
Ginger: 2 papayas
Professor: 3 coconuts
MaryAnn: 2 papayas
...

He wants to write a series of files, called gilligan.info, maryann.info, and so on. Each file should contain all the lines that begin with that name. (Names are always delimited by the trailing colon.) At the end, gilligan.info should start with:

Gilligan: 1 coconut
Gilligan: 1 banana

Now the logfile is large, and the coconut-powered computer is not very fast, so he wants to process the input file in one pass and write all output files in parallel. How does he do it?

Hint: use a hash, keyed by the castaway name, holding IO::File objects for each output file. Create them as necessary.

8.6.3. Exercise 3 [15 min]

Write a program that takes in multiple directory names from the command line, then prints out their contents. Use a function that takes a directory handle reference that you made using IO::Dir.


Previous
Table of Contents
Next
© 2000- NIV