meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Thursday, August 24, 2006

Unix Tip: More on associative arrays

By Sandra Henry-Stocker

An associative array, when implemented in Perl, has come to be known as a "hash" -- a word that is also used to describe the digested value (i.e., the "message digest") generated from a longer piece of text and used to ensure that the text has not been altered (if a message before
and after transmission results in the same hash, the text can assume to be unaltered).

This choice of the word "hash" for a seemingly unrelated use is not surprising when the function of a hash is considered. The value of each hash element is computed from its key in a manner that is not entirely dissimilar from the way in which message digests are computed from the text that they represent -- thus, the concept of computing a "hash" that leads to the proper data value for an element in the array.

Using the array from last week's column, the wavelength of various rainbow colors can be assigned to a hash in several different ways. In one of the assignments we looked at last week, the hash elements were set up in one command that incorporated key/value groups using separate lines to clarify the relationships between the color names and wavelength values:

Read the full article here

0 Comments:

Post a Comment

<< Home