Gossamer Forum
Home : General : Perl Programming :

Associative Arrays

Quote Reply
Associative Arrays
Hi:

Unfamiliar with 'associative arrays', I need to place the following (data extracted from user files in a for..loop) in an associative array (%data) where the key is $user:

($a, $b, $c) = split (/\|/, $data);

Then having done that, how do I extract the array elements singly? For example, extract the value for $b for a particular user.

Dan Smile
Quote Reply
Re: Associative Arrays In reply to
Hi Dan,

As you go through the for loop, build the associative array:

$userdata{$a} = $b;

assuming $a is the userid, and $b is the data you want. Then you can just access it normally afterwards.

Hope that helps,

Alex