Associative arrays are Perl's implementation of hash tables. Associative arrays are arguably the most unique and useful feature of Perl. Common applications of associative arrays include creating tables of users keyed on login name and creating tables of file names. The prefix for associative arrays is the percent sign (%).
Associative arrays are keyed on strings (numeric keys are interpolated into strings). An associative array can be explicitly declared as a list of key-value pairs. For example:
%quota = ("root",100000, "pat",256, "fiona",4000);
Associative arrays elements are referenced in the following way:
$quota{dave} = 3000;
In this case, "dave"
is the key and 3000 is the value. Note
that the reference above is to a scalar and is thus prefixed by a $.
Here is another example. In Perl scripts, there is a predefined associative array called %ENV which contains all of the environment variables of the calling environment. Here is a bit of Perl code to see if you are running X Windows:
if ($ENV{DISPLAY}) { print "X is (probably) running\n"; }
There are routines for traversing the contents of associative arrays and for deleting elements. The relevant Perl routines are each, keys, values, and delete.
Note that the namespace for Perl variables is exclusive. One can refer to scalars, arrays, associative arrays, subroutines, and packages with the same name without fear of conflict.