And if you're really stuck with using arrays, you can always:

my @bases = ();
my $first = 0;

$bases[$first] = 'who';

-----Original Message-----
From: Johnstone, Colin
To: 'chris'
Cc: '[EMAIL PROTECTED]'
Sent: 10/19/02 5:47 PM
Subject: RE: A better way to handle array index?

That would be a hash. (or an associative array)

for example I read my form variables into a hash for processing. 

I then reference them by the form fieldname.

#read STDIN, $PostData, $ENV{'CONTENT_LENGTH'};

#print "post data =$PostData<br>";

#postdata will look like this
#[EMAIL PROTECTED]&radAction=unsubscribe&radFo
rmat=html&Submit=Submit
#I need to extract from this string the fields and their values
my @fields = split( /\&/, $PostData);

#Once extracted I write the fieldnames and their values to the formData
Hash
#the index is the fieldname from the form
foreach $_ ( @fields ){
  @data = split( /=/, $_ );
  $formData{$data[0]} = $data[1];
}

#This routine is used to check the values in the form data hash for
debugging purposes
# while(($k,$v)=each(%formData)){
#   print"$k => $v<br>";
# }


# I access the values of the fields by calling them as below
# another name for a has is an associative array
# print "<br>Email Address =".$formData{'txtEmailAddr'}."<br>";
# print "Action =".$formData{'radAction'}."<br>";
# print "Format =".$formData{'radFormat'}."<br>";

-----Original Message-----
From: chris [mailto:chris@;home.com]
Sent: Sunday, October 20, 2002 10:40
To: [EMAIL PROTECTED]
Subject: A better way to handle array index?


I am looking for a less cryptic way to handle array index.

most cryptic
$array[0]

better
use constant NAME => 0;
$array[NAME]

Any ideas?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to