Hash Review/Lab
-
Hashes are like arrays, but associate a key and value instead of an index
number and value.
-
You can get a value by its key, get all values, or get all keys.
-
There are more functions in the book that we will not cover: removing keys/values,
checking to see if a key exists.
-
Why use this?
-
Imagine saving keys and values to a file. You can read these keys
and values into a hash, and then do with them as you please.
-
You already do use this. Remember $query->param{'city'}
?
-
Now, the Lab:
-
Write a Perl script with a hash.
-
In the hash, the keys should be names of pets you have had (make some up
if you never had pets), and the values should be the type of animal (dog,
cat, bird, snake, etc.).
-
Print the name and type in an HTML doc.
-
Hints:
Subroutines
Home