Perh Hash of Hash of Array structure

S

Shiraz

I am programing with a hash structure for a cache. The code is below.
The part dont understand, is that in the output why does "'prefix4' =>
$VAR2->{'key2'}{'key3'}{'class'}{'prefix5'}," show up unlike an array.
All the others show up as arrays but not this one. Does this mean that
i am making a wrong assignment? Is my code bad in the assignments? Or
is it just a display problem with the Data::Dumper module?

Thanks for any suggestions



=CODE=====================================
use strict;
use warnings;
use Data::Dumper;

my %acctMap=();

my @r = ( "fred", "barney", "pebbles", "bamm bamm", "dino" );

%{$acctMap{'key1'}{'key2'}{'key3'}{'class'}} = (
prefix1 => [ "george1", "jane2", "el3roy" ],
prefix2 => [ "george", "jane", "elroy" ],
prefix3 => [ "george", "jane", "elroy" ],
);

$acctMap{'key1'}{'key2'}{'key3'}{'class'}{'prefix4'} = \@r;
$acctMap{'key1'}{'key2'}{'key3'}{'class'}{'prefix5'} = \@r;
$acctMap{'key1'}{'key2'}{'key3'}{'class'}{'prefix6'} = \@r;

print Dumper(%acctMap);

exit;

=CODE=====================================



=OUTPUT=====================================
$VAR1 = 'key1';
$VAR2 = {
'key2' => {
'key3' => {
'class' => {
'prefix5' => [
'fred',

'barney',

'pebbles',
'bamm
bamm',
'dino'
],
'prefix6' => $VAR2-
{'key2'}{'key3'}{'class'}{'prefix5'}, 'prefix4' => $VAR2-
{'key2'}{'key3'}{'class'}{'prefix5'},
'prefix1' => [

'george1',
'jane2',
'el3roy'
],
'prefix3' => [

'george',
'jane',
'elroy'
],
'prefix2' => [

'george',
'jane',
'elroy'
]
}
}
}
};
=OUTPUT=====================================
 
J

John W. Krahn

Shiraz said:
I am programing with a hash structure for a cache. The code is below.
The part dont understand, is that in the output why does "'prefix4' =>
$VAR2->{'key2'}{'key3'}{'class'}{'prefix5'}," show up unlike an array.

That is because $acctMap{key1}{key2}{key3}{class}{prefix4},
$acctMap{key1}{key2}{key3}{class}{prefix5} and
$acctMap{key1}{key2}{key3}{class}{prefix6} all point to the same array so
Data::Dumper can't create three separate arrays because there is only one
array so the other two point to that array.



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,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top