Exercises

  1. Create a complex data structure as follows:

    1. Create a hash called %pizza_prices which contains prices for small, medium and large pizzas.

    2. Create a hash called %pasta_prices which contains prices for small, medium and large serves of pasta.

    3. Create a hash called %milkshake_prices which contains prices for small, medium and large milkshakes.

    4. Create a hash containing references to the above hashes, so that given a type of food and a size you can find the price of it.

    5. Convert the above hash to use anonymous data structures instead of the original three pizza, pasta and milkshake hashes

    6. Add a new element to your hash which contains the prices of salads

    (Answer: exercises/answers/food.pl)

  2. Create a subroutine which can be passed a scalar and a hash reference. Check whether there is an element in the hash which has the scalar as its key. Hint: use exists for this. (Answer: exercises/answers/exists.pl)