hash of hashes, and arrays, help!

W

woodenbicycle

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!
 
G

Gunnar Hjalmarsson

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

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

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

John W. Krahn

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
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top