Section 5.9.  Exercises

Table of Contents

5.9. Exercises

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

5.9.1. Exercise 1 [5 min]

Without running it, can you see what's wrong with this piece of a program? If you can't see the problem after a minute or two, see whether trying to run it will give you a hint of how to fix it.

my %passenger_1 = {
  name       => 'Ginger',
  age        => 22,
  occupation => 'Movie Star',
  real_age   => 35,
  hat        => undef,

my %passenger_2 = {
  name          => 'Mary Ann',
  age           => 19,
  hat           => 'bonnet',
  favorite_food => 'corn',

my @passengers = (\%passenger_1, \%passenger_2);

5.9.2. Exercise 2 [40 min]

The Professor's datafile (mentioned earlier in this chapter) is available as coconet.dat in the files you can download from the O'Reilly web site. There may be comment lines (beginning with a pound sign); be sure to skip them. (That is, your program should skip them. You might find a helpful hint if you read them!)

Modify the code from this chapter so that each source machine's portion of the output shows the total number of bytes from that machine. List the source machines in order from most to least data transferred. Within each group, list the destination machines in order from most to least data transferred to that target from the source machine.

The result should be that the machine that sent the most data will be the first source machine in the list, and the first destination should be the machine to which it sent the most data. The Professor can use this printout to reconfigure the network for efficiency.

Table of Contents
© 2000- NIV