Pulling scalars out of lists and hashes

Note that list indexing starts by default at 0. You can actually change this by setting the special $[ variable.

Let's set up a list;

@names = (alpha, beta, gamma, delta);

$names[0];

Hashes are special lists in which you look up elements NOT by position, but by using a key string. Here's an example of initializing a hash:

%letters = ( A => alpha,
             B => beta,
             G => gamma,
             D => delta);

A single element is returned by accessing the hash through the key, as in $letters{G}.

You can get at the keys in a hash using the keys command, and the values by the values command.



Richard Waterman
Fri Jan 22 01:27:29 EST 1999