Basic HTML version of Foils prepared Sept 20 97

Foil 30 Hashes -- Definition

From Tutorial on PERL Computational Science for Information Age Course CPS616 -- Sept 20 97. by Geoffrey C. Fox,Nancy McCracken,Tom Scavo


1 A hash (sometimes called an associative array) is a "software implemented" associative memory where values are fetched by names or attributes called keys
2 A hash is a set of pairs (key, value)
3 The entire array is referred to as %dict (for example):
  • $dict{key} = value; # NOTE curly braces {} to denote hash
4 The values can be used in ordinary arithmetic such as
  • $math{pi} = 3.14; $math{pi} += .0016; # sets $math{pi} = 3.1416;
  • either pi or 'pi' is allowed for specifying key
5 If key pimisspelt is undefined then $math{pimisspelt} returns undef and so one can easily see if a particular key has a value
6 Alternatively, the function exists($math{pimisspelt}) returns false unless key pimisspelt has a value

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sun Sep 21 1997