Front page | perl.beginners |
Postings from September 2009
AW: Hash of Hashes
Thread Previous
|
Thread Next
From:
Thomas Bätzler
Date:
September 29, 2009 03:16
Subject:
AW: Hash of Hashes
Message ID:
E350C77ABFDBD242BDD51F5DA07905C104B5564D@SONNE.gw.bringe.net
Soham Das <sohamdas@yahoo.co.in> 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?
I.e.:
%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'] );
HTH,
Thomas
Thread Previous
|
Thread Next