Quick Associative Array Question

Discussion in 'Perl Misc' started by amerar@iwc.net, Dec 5, 2005.

  1. Guest

    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.
    , Dec 5, 2005
    #1
    1. Advertising

  2. 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?
    it_says_BALLS_on_your forehead, Dec 5, 2005
    #2
    1. Advertising

  3. Guest

    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
    , Dec 5, 2005
    #3
  4. wrote in
    news::

    > 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/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Dec 5, 2005
    #4
  5. 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
    `$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
    $!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
    $_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
    ;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
    Eric J. Roode, Dec 6, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JKop
    Replies:
    11
    Views:
    852
  2. desktop
    Replies:
    5
    Views:
    373
    James Kanze
    Jun 26, 2007
  3. Yvon Thoraval
    Replies:
    5
    Views:
    198
    Jason Creighton
    Sep 17, 2003
  4. VK
    Replies:
    47
    Views:
    511
    Thomas 'PointedEars' Lahn
    Jul 13, 2005
  5. VK
    Replies:
    36
    Views:
    618
    Martin Honnen
    Aug 3, 2005
Loading...

Share This Page