Hash Table

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 15 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Hash Table

Post by jvierra »

That's correct.

It's important to note that the "value" portion of key/value can be any sort of object including another hash.

Code: Select all

$people = @{}
	

$valuehash=@{}
$valuehash.Add( "name", "joe")
$valuehash.Add("age", 23)
$people.Add( "joe's info", $valuehash)

	
$valuehash=@{}
$valuehash.Add( "name", "mary")
$valuehash.Add("age", 23)
$people.Add( "mary's info", $valuehash)

	
$people.GetEnumerator()|sort name|%{$_.Value|ft}
	



You can take this to any reasonable depth although complexities greater than two call for use of either XML or a database.



User avatar
jkavanagh58
Posts: 17
Last visit: Wed Jan 17, 2018 11:51 am

Hash Table

Post by jkavanagh58 »

Now my head is spinning... just kidding, thanks for all of the great help!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Hash Table

Post by jvierra »

# LAST-IN-FIRST-OUT$i=0$stack = new-object system.collections.Stack$stack.Push($i++)$stack.Push($i++)$stack.Push($i++)$stack.Push($i++)$stack.Push($i++)$stack.Push($i++)$stack.Pop()$stack.Pop()$stack.Pop()
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Hash Table

Post by jvierra »

As a closing note.

I posted all of that other nonsense because I think it helps to think of these things as a collection of related processes or concepts.

Dictionary, Collecion, List, Sortedlist, HashTable, ArrayList, Stack, Queue and others are all related. They each add a custom way to store and retrieve information. By seeig them all at once sometimes we get an insight into the current problem which wil allow us to approach it in a new way that may simlpify the task.

Besides...it never hurts to have too many tools. (or maybe I'm just a packrat )
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Hash Table

Post by jvierra »

I am very much in favor of frosty beverages. Come back and we wil see if we can give you another excuse for one.

Hell - I'm going to have one myself...
This topic is 15 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked