Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Accessing an Associative Array

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.

Additional Resources:

Perl Associative Arrays
Table of Contents
Using the keys and values functions


Up to => Home / Authoring / Scripting / Tutorial




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers