Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > hash of hashes, and arrays, help!

Reply
Thread Tools

hash of hashes, and arrays, help!

 
 
woodenbicycle@hotmail.com
Guest
Posts: n/a
 
      03-15-2006
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!

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      03-15-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      03-15-2006
(E-Mail Removed) 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
 
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
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Hash#select returns an array but Hash#reject returns a hash... Srijayanth Sridhar Ruby 19 07-02-2008 12:49 PM
[Nuby] Sorting a Hash and keepint it as a Hash? Williams, Chris Ruby 3 12-13-2004 09:04 PM
Hash#eql? and Hash key testing Joel VanderWerf Ruby 4 12-04-2004 02:11 PM
standard library for hash table storage and hash algorithm Pieter Claassen C Programming 1 08-04-2004 03:11 AM



Advertisments