Basic HTML version of Foils prepared March 30 97

Foil 29 Associative Arrays -- Definition
(Chapter 5 of the Llama Book)

From PERL4 Tutorial for CPS616 Computational Science for Information Age Course CPS616 -- February 1995. by Geoffrey C. Fox


1 An associative array is a "software implemented" associative memory where you can fetch values by names or attributes or technically keys
2 An associative array is a set of pairs (key,value).
3 The whole array is referred to as %dict and is typically set with instructions like
  • $dict{keyname} = value; # NOTE Curly braces {} to show array associative
4 The values can be used in ordinary arithmetic such as
  • $math{pi}=3.14; $math{pi} += .0016; # sets $math{pi}=3.1416;
  • pi or "pi" is allowed for specifying key
5 If key pimisspelt has not been defined then $math{pimisspelt} returns undef as value and so one can easily see if a particular key has been set.
6 Alternatively function exists($math{pimisspelt}) returns false unless key pimisspelt has been set

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 Sat Sep 6 1997