Basic HTML version of Foils prepared March 30 97

Foil 32 Associative Arrays -- Operators: keys, values, each (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 keys(%dict) returns a list (conventional array) of keys in %dict ( in arbitrary order). This can be used with foreach construct
2 foreach (keys(%mime)) { # $_ will run through keys
  • print "In dictionary we have key $_ as $mime{$_}\n";
  • }
3 values(%dict) is typically less useful. It returns a list of values (which may be repeated) in any order in associative array %dict
4 each(%dict) returns a single two element list containing the "next" (key,value) pair in %dict.
  • Each call to each(%dict) returns a new such pair until all are cycled through.
  • Finally each will return a null (undefined) list.
  • After this, next call to each will start the cycle again through the entire list of pairs in %dict

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