Perl Associative Arrays 

What is an associative array?
  • Associative Arrays add the final degree of complexity allowing ordered lists to be associated with other values. Unlike list arrays, associative arrays have index values that are not numbers. You do not reference an associative array as $associative_array_name[0] as you did for the list array. Instead, associative arrays are indexed with arbitrary scalar variables. Consider the following associative array definition: 
  • %CLIENT_ARRAY = ('full_name', 'Selena Sol',
                     'phone', '213-456-7890', 
                     'age', '27'); 
  • In this example, we have defined the associative array %CLIENT_ARRAY to have three sets of associations. 
The percent sign (%) denotes the associative array name just as the dollar sign ($) did for variables and the at sign (@) did for list arrays.
  • Thus, "full_name" is associated with "Selena Sol" as "age" is associated with "27". This association is discussed in terms of "keys" and "values". Each key is associated with one value. Thus, we say that the key "full_name" is associated with the value "Selena Sol". 

Additional Resources:

Deleting and replacing list elements with the splice function
Table of Contents
Accessing an Associative Array


Graphics & Media Lab. >> Библиотека | Курсы | Графикон

Hosted by Graphics & Media Lab
http://graphics.cs.msu.su
lab_logo
mailto: Laboratory