Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Quick Associative Array Question

Reply
Thread Tools

Quick Associative Array Question

 
 
amerar@iwc.net
Guest
Posts: n/a
 
      12-05-2005
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.

 
Reply With Quote
 
 
 
 
it_says_BALLS_on_your forehead
Guest
Posts: n/a
 
      12-05-2005

ame...@iwc.net wrote:
> 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?

 
Reply With Quote
 
 
 
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      12-05-2005
ame...@iwc.net wrote:
> 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.

--
http://DavidFilmer.com

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      12-05-2005
wrote in
news: ps.com:

> 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
--
A. Sinan Unur <>
(reverse each component and
remove .invalid for email address)

comp.lang.perl.misc guidelines on
the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
Eric J. Roode
Guest
Posts: n/a
 
      12-06-2005
wrote in news:1133810599.606273.5860
@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
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why "associative" in associative container? desktop C++ 5 06-26-2007 07:49 AM
Array and Hash (Associative array) in JavaScript v.3.0 VK Javascript 36 07-30-2005 03:21 PM
<FAQENTRY> Array and hash (associative array) VK Javascript 47 07-13-2005 06:27 AM
How to read associative array from file? nospam Perl 2 06-26-2004 09:46 AM
[newbie]saving and reading array of associative array Yvon Thoraval Ruby 5 09-17-2003 07:54 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57