hash of hashes, and arrays, help!

Discussion in 'Perl Misc' started by woodenbicycle@hotmail.com, Mar 15, 2006.

  1. Guest

    I hit a snag and am lost. Here is a piece of a testcase of what I'm
    tyring to do:

    $catalog{$title}{"genre"} = "Romance";
    $catalog{$title}{"rating"} = "PG-13";
    my @tempkeywordlist = ("Paris","Sailboats,"Summer");
    @catalog{$title}{"keywords"} = @tempkeywordlist;
    ....
    ### @tempkeywordlist is later destroyed/overwritten ###
    ....
    my @keywords = @catalog{$title}{"keywords"};
    foreach (@keywords){print("Keyword: $_ \n");}

    Obviously this isn't working. I have tried various combinations of ways
    to put the array into the hash, and later copy it out, but have had no
    success. I tried using the square brackets, but that only gave me a
    reference that I was unable to make use of. I tried using
    $catalog{$title{"keywords"} but it only gave me the size of the array,
    not the array itself. Help!
     
    , Mar 15, 2006
    #1
    1. Advertising

  2. wrote:
    >
    > my @tempkeywordlist = ("Paris","Sailboats,"Summer");
    > @catalog{$title}{"keywords"} = @tempkeywordlist;


    $catalog{$title}{'keywords'} = \@tempkeywordlist;

    > my @keywords = @catalog{$title}{"keywords"};


    my @keywords = @{ $catalog{$title}{'keywords'} };

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Mar 15, 2006
    #2
    1. Advertising

  3. wrote:
    > I hit a snag and am lost. Here is a piece of a testcase of what I'm
    > tyring to do:
    >
    > $catalog{$title}{"genre"} = "Romance";
    > $catalog{$title}{"rating"} = "PG-13";
    > my @tempkeywordlist = ("Paris","Sailboats,"Summer");
    > @catalog{$title}{"keywords"} = @tempkeywordlist;
    > ...
    > ### @tempkeywordlist is later destroyed/overwritten ###
    > ...
    > my @keywords = @catalog{$title}{"keywords"};
    > foreach (@keywords){print("Keyword: $_ \n");}
    >
    > Obviously this isn't working. I have tried various combinations of ways
    > to put the array into the hash, and later copy it out, but have had no
    > success. I tried using the square brackets, but that only gave me a
    > reference that I was unable to make use of. I tried using
    > $catalog{$title{"keywords"} but it only gave me the size of the array,
    > not the array itself. Help!



    $catalog{ $title }{ keywords } = [ 'Paris', 'Sailboats', 'Summer' ];

    Or:

    my @tempkeywordlist = ( 'Paris', 'Sailboats', 'Summer' );
    @{ $catalog{ $title }{ keywords } } = @tempkeywordlist;

    Or:

    my @tempkeywordlist = ( 'Paris', 'Sailboats', 'Summer' );
    $catalog{ $title }{ keywords } = \@tempkeywordlist;


    perldoc perldata
    perldoc perldsc
    perldoc perllol
    perldoc perlreftut
    perldoc perlref



    John
    --
    use Perl;
    program
    fulfillment
     
    John W. Krahn, Mar 15, 2006
    #3
    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. Tore Aursand
    Replies:
    3
    Views:
    557
    Anno Siegel
    Sep 16, 2003
  2. Scott  Gilpin
    Replies:
    2
    Views:
    221
  3. Perl Learner

    Hashes of hashes or just one hash ?

    Perl Learner, Jun 8, 2005, in forum: Perl Misc
    Replies:
    11
    Views:
    216
  4. Tim O'Donovan

    Hash of hashes, of hashes, of arrays of hashes

    Tim O'Donovan, Oct 27, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    214
  5. Replies:
    3
    Views:
    208
Loading...

Share This Page