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

Re: AW: Hash of Hashes

Thread Previous | Thread Next
Soham Das
September 29, 2009 03:36
Re: AW: Hash of Hashes
Message ID:
Yes,its much more powerful, the way you said, but in my case it won't be necessary or important. 

Here I guess, I gave a wrong example where the data can be changed. 

Lets assume, the hash of hash being a record of something which has already happened and hence we know the final value, not something which is right now happening, i.e changeable. 

In my case, its like

$Position{$Scrip}{$Date}= #some value 

That is, my position in a previous date $Date, in the stock $scrip, was some integer. Thanks for the correction, regarding the brackets. I stand corrected and it seems I have made a lot of such mistakes apparent in the previous two three mails.


From: Thomas Bätzler <>
Cc: Soham Das <>
Sent: Tuesday, 29 September, 2009 3:46:28 PM
Subject: AW: Hash of Hashes

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'] );


      Connect more, do more and share more with Yahoo! India Mail. Learn more.
Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About