Using Nested Hash Tables

by Jun 24, 2014

Nested hash tables can be a great alternative to multidimensional arrays. They can be used to store data sets in an easy-to-manage way. Have a look:

$person = @{}
$person.Name = 'Weltner'
$person.Id = 12
$person.Address = @{}
$person.Address.Street = 'Canyon Rim'
$person.Address.City = 'Folsom'
$person.Address.Details = @{}
$person.Address.Details.Story = 4
$person.Address.Details.ScenicView = $false

This would define a person. You can always view the entire person:

PS> $person
Name Value
---- -----
Name Weltner
Id 12
Address {Street, Details, City}

You can just as easily retrieve individual pieces of information:

PS> $person
Name
Weltner

PS> $person.Address.City
Folsom

PS> $person.Address.Details.ScenicView
False

Twitter This Tip! ReTweet this Tip!