11.8 Exercise


The answers for all exercises can be found in Section A.10.

11.8.1 Exercise [30 min]

The Professor has to read a log file 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 log file 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.



Learning Perl Objects, References & Modules
Learning Perl Objects, References, and Modules
ISBN: 0596004788
EAN: 2147483647
Year: 2003
Pages: 199

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net