DekGenius.com
[ Team LiB ] Previous Section Next Section

4.9 Exercises

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

4.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);

4.9.2 Exercise 2 [30 min]

The Professor's data file (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 the 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.

    [ Team LiB ] Previous Section Next Section