Accessing an Associative Array

If we want to extract a value from the associative array, we reference it with the following syntax:

$variable = $ASSOCIATIVE_ARRAY{'key'};

Thus, to pull out the value of the "full_name" key from %ASSOCIATE_ARRAY, we use the following syntax:

$full_name = $ASSOCIATE_ARRAY{'full_name'};

The variable $full_name would then be equal to "Fred Derf ".
Think of $full_name as using the "key" to unlock the "value", "Fred Derf".

Exercise
Build an associative array consisting of

Write a short perl script to retrieve your age and place it in the variable $myage and print it

When accessing an associative array using a scalar variable as a key, you should surround the key with double quotes otherwise the scalar variable will not be interpolated.
For example, the following syntax generates the value for the age key

$key_name = "age";
$age = $ASSOCIATE_ARRAY{$key_name};

Accessing an associative array is one of the most basic CGI functions and is at the heart of any Parse routine that creates an associative array from the incoming web form data.

By accessing this associative array (usually referred to as %in or %form_data), your CGI script will be able to manipulate the data the client has entered on the web form as an array of key/value pairs.

For example, with the textbox below called full_name

<input type="text" name="full_name" size="40" />

The "key" will be "full_name" and the "value" will be whatever the client typed into the text box.