September 2002
Intermediate to advanced
496 pages
10h
English
If you have not seen hashes before, you might be amazed at the places where they can be used. The following examples show some application areas where this data type is useful. Notice in these examples that the hashes are built dynamically in response to the requirements of the program. This is different from the %groups hash above, where that hash was initialized before accepting user input.
This example demonstrates how to use a hash to count the frequency of words in a file. The strategy is to read lines from a file and split each line into its words. Then each word can be used as an index into a hash where the associated value can be the count for each word. Here is the code. See the folder