Blob


1 #!/usr/bin/perl
3 # Modify the crew roster program to add a location field for each castaway.
4 # At the start, set each person's location to "The Island." After you've
5 # added that field to each person's hash, change the Howells' locations to
6 # "The Island Country Club." Make a report of everyone's location, like
7 # this:
8 #
9 # Gilligan at the Island
10 # Skipper at the Island
11 # Mr. Howell at the Island Country Club
12 # Mrs. Howell at the Island Country Club
14 use v5.24;
15 use warnings;
16 use strict;
17 use utf8;
19 my %gilligan_info = (
20 name => 'Gilligan',
21 hat => 'White',
22 shirt => 'Red',
23 position => 'First Mate',
24 );
25 my %skipper_info = (
26 name => 'Skipper',
27 hat => 'Black',
28 shirt => 'Blue',
29 position => 'Captain',
30 );
31 my %mrhowell_info = (
32 name => 'Mr. Howell',
33 hat => undef,
34 shirt => 'White',
35 position => 'Passenger',
36 );
37 my %mrshowell_info = (
38 name => 'Mrs. Howell',
39 hat => undef,
40 shirt => undef,
41 position => 'Passenger',
42 );
44 my @crew = (\%gilligan_info, \%skipper_info, \%mrhowell_info, \%mrshowell_info);
46 foreach my $crewmember (@crew) {
47 $crewmember->{location} = 'The Island';
48 }
50 sub location {
51 foreach (@_) {
52 printf("%s at %s\n", $_->{name}, $_->{location});
53 }
54 }
55 location(@crew);
56 $mrhowell_info{location} = 'The Island Country Club';
57 $mrshowell_info{location} = 'The Island Country Club';
58 location(@crew);