Check Out Nested Hash Tables

by Jul 10, 2012

In our last tip we looked at nested arrays (jagged arrays) which may have been a bit confusing. Today, we look at nested hash tables. They may look even more confusing but can be highly useful. Here are two hash tables—note how $hash2 is placed into the other hash table called $person:

$hash2 = @{
    id = 1
    age = 99
    group = 'PS Programmers'

$person = @{
    name = 'Weltner'
    firstname = 'Tobias'
    more = $hash2

And here is how you can access or update the data:

PS> $person

Name                           Value                                                                                                   
----                           -----                                                                                                   
more                           {group, age, id}                                                                                        
name                           Weltner                                                                                                 
firstname                      Tobias                                                                                                  

PS> $

PS> $person.more

Name                           Value                                                                                                   
----                           -----                                                                                                   
group                          PS Programmers                                                                                          
age                            99                                                                                                      
id                             1                                                                                                       

PS> $
PS Programmers

PS> $
PS> $ = 111

Twitter This Tip! ReTweet this Tip!