I need to know the way of creating the associative array in Perl.
Basically, now I have the code which is implemented as follows:
my $getEmployeeListOfTeamQuery = "SELECT profiles.userid
FROM user_group_map,profiles
WHERE user_group_map.group_id = $teamId
AND profiles.userid = user_group_map.user_id
AND profiles.active = 'y'
AND profiles.login_name NOT LIKE 'qa_%'
AND profiles.disabledtext = ''
GROUP BY profiles.login_name
ORDER BY profiles.login_name";
my $getEmployeeListOfTeam = $dbh->prepare($getEmployeeListOfTeamQuery);
$getEmployeeListOfTeam -> execute();
my @techs = ();
while(my ($tech) - $getEmployeeListOfTeam->fetchrow_array) {
push @techs,$tech;
}
So the above code will be having the query in $getEmployeeListOfTeamQuery. It created the array names as techs.
Then I tried pushing the values into the array.
Here it is working fine.
My question here is regarding the creation of the associative array.
That is, I need to query as follows: "SELECT profiles.userid, profiles,username....."
Hence I need to create an associative array with "userid" as the key and "username" as the value.
fetchrow_hashref()returns.fetchrow_hashref()gives you. Usingfetchrow_hashref()would give a data structure like{ userid => "foo", username => "bar" }. The question asks for a structure like{ foo => "bar"}.