develooper Front page | perl.beginners | Postings from September 2009

AW: Hash of Hashes

Thread Previous | Thread Next
Thomas Bätzler
September 29, 2009 03:16
AW: Hash of Hashes
Message ID:
Soham Das <> asked:
> How can I create a Hash of Hashes from two lists. Is it possible?
> I want the effective functionality to be served like this
> $ChildHash["Joe"]["21A"]="Sally"
> i.e Joe at 21A has a child called Sally. List1 here will be the name of
> Parents, List2 here will contain the house number.

Please keep in mind: square brackets are for arrays/lists. Curly brackets are for hashes.

In any case, wouldn't it be smarter to organize your data differently?


%parent = ( 'Joe' => { 'address' => '21A', children => ['Dick','Sally'] } );

To add another child to an existing parent you'd then say

	push @{$parent{'Joe'}{'children'}}, 'Jane';

To add a new parent:

	@{$parent{'Sven'}}{'address','children'} = ( '9b', ['Bjorn'] );


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About