Quick Associative Array Question

A

amerar

Hi All,

Can I create an associative array where the key is the value of another
associative array?

Say I have the following:

$FORM{'name'} = 'JohnDoe';

Then, I want to create $names{$FORM{'name'}} = some value

That is not working, but I want to create an associative array where
the key is the value from another associative array without having to
assign an interium variable........

Any help with the syntax?

Thanks.
 
I

it_says_BALLS_on_your forehead

Hi All,

Can I create an associative array where the key is the value of another
associative array?

Say I have the following:

$FORM{'name'} = 'JohnDoe';

Then, I want to create $names{$FORM{'name'}} = some value

That is not working, but I want to create an associative array where
the key is the value from another associative array without having to
assign an interium variable........

Any help with the syntax?

what do you mean by 'not working'? what are your results?
 
U

usenet

Say I have the following:
$FORM{'name'} = 'JohnDoe';
Then, I want to create $names{$FORM{'name'}} = some value
That is not working

What do you mean, 'not working?' This works:

#!/usr/bin/perl
use warnings; use strict;

my %form;
$form{'name'} = 'JohnDoe';

my %names;
$names{$form{'name'}} = 'some value';

print $names{'JohnDoe'};
__END__

#### output: "some value"

Show us some more code, or tell us more specifically what the problem
(and/or goal) is.
 
A

A. Sinan Unur

(e-mail address removed) wrote in
Can I create an associative array where the key is the value of
another associative array?

Yes.

Please consult the posting guidelines for this group for help on how to
formulate a question to increase your chances of receiving useful replies.

Sinan
 
E

Eric J. Roode

(e-mail address removed) wrote in @f14g2000cwb.googlegroups.com:
Say I have the following:

$FORM{'name'} = 'JohnDoe';

Then, I want to create $names{$FORM{'name'}} = some value

That is not working, but I want to create an associative array where
the key is the value from another associative array without having to
assign an interium variable........

Any help with the syntax?

Your syntax is perfectly fine. You claim that it is "not working" -- not
very useful. (Do you take your car to the mechanic, say "it's not
working", and walk away?)

--
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top