eXtropia: the open web technology company
Technology | Support | Tutorials | Development | About Us | Users | Contact Us
Resources
 ::   Tutorials
 ::   Presentations
Perl & CGI tutorials
 ::   Intro to Perl/CGI and HTML Forms
 ::   Intro to Windows Perl
 ::   Intro to Perl 5
 ::   Intro to Perl
 ::   Intro to Perl Taint mode
 ::   Sherlock Holmes and the Case of the Broken CGI Script
 ::   Writing COM Components in Perl

Java tutorials
 ::   Intro to Java
 ::   Cross Browser Java

Misc technical tutorials
 ::   Intro to The Web Application Development Environment
 ::   Introduction to XML
 ::   Intro to Web Design
 ::   Intro to Web Security
 ::   Databases for Web Developers
 ::   UNIX for Web Developers
 ::   Intro to Adobe Photoshop
 ::   Web Programming 101
 ::   Introduction to Microsoft DNA

Misc non-technical tutorials
 ::   Misc Technopreneurship Docs
 ::   What is a Webmaster?
 ::   What is the open source business model?
 ::   Technical writing
 ::   Small and mid-sized businesses on the Web

Offsite tutorials
 ::   ISAPI Perl Primer
 ::   Serving up web server basics
 ::   Introduction to Java (Parts 1 and 2) in Slovak

 

introduction to web programming
Accessing an Associative Array  
If we want to extract a value from the associative array, we reference it with the following syntax:

    $variable_equal_to_value =
    $ASSOCIATIVE_ARRAY_NAME{'[key]'};

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

    $full_name = $CLIENT_ARRAY{'full_name'}

The variable $full_name would then be equal to "Selena Sol". Think of it as using a "key" to unlock a "value".

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

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

Accessing an associative array is one of the most basic CGI functions and is at the heart of the ReadParse routine in cgi-lib.pl that creates an associative array from the incoming form data. We will talk more about ReadParse later today.

By accessing this associative array (usually referred to as %in or %form_data), your CGI script will be able to determine what it is that the client has asked of it since HTML form variables are formed in terms of administratively-defined NAMES and client-defined VALUES using syntax such as the following:

    <INPUT TYPE = "text" NAME = "full_name"
           SIZE = "40">

The "key" of the associative array generated by ReadParse will be "full_name" and the "value" will be whatever the client typed into the text box.

Previous | Next | Table of Contents