Section 4.9. Exercises


4.9. Exercises

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

4.9.1. Exercise 1 [5 min]

How many different things do these expressions refer to?

 $ginger->[2][1] ${$ginger[2]}[1] $ginger->[2]->[1] ${$ginger->[2]}[1] 

4.9.2. Exercise 2 [30 min]

Using the final version of check_required_items, write a subroutine check_items_for_all that takes a hash reference as its only parameter, pointing at a hash whose keys are the people aboard the Minnow and whose corresponding values are array references of the things they intend to bring onboard.

For example, the hash reference might be constructed like so:

 my @gilligan  = ... gilligan items ...; my @skipper   = ... skipper items ...; my @professor = ... professor items ...; my %all = (   Gilligan  => \@gilligan,   Skipper   => \@skipper,   Professor => \@professor, ); check_items_for_all(\%all); 

The newly constructed subroutine should call check_required_items for each person in the hash, updating their provisions list to include the required items.




Intermediate Perl
Intermediate Perl
ISBN: 0596102062
EAN: 2147483647
Year: N/A
Pages: 238

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