Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 01-06-2009
Member
 
Join Date: May 2008
Posts: 979
Powershell: declare hash table

I am learning PowerShell. I would like to know how to declare the hash table in PowerShell? Also what is the actual usage of hash table? What are are the benefits of it?
Reply With Quote
  #2  
Old 01-06-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Powershell: declare hash table

PowerShell Hash Table allows you to store key-value pairs. It is an array that allows you to store data in a ?key-value? pair association. The ?key? and ?value? entries can be any data type and length. The elements must be quoted if they contain a space.

Just like an array, a hash table is declared with "@" symbol. The hash ?key-value? pairs are enclosed in curly brackets {} and its elements are separated by the semi-colon.

To create a hash table:

$EmpName = @{"Alap"; "Sanjay"; "Arpita"}

Source: powershellpro
Reply With Quote
  #3  
Old 01-06-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Powershell: declare hash table

A hash table is simply a collection of name-value pairs, very much like the FileSystemObject?s Dictionary object. For example, suppose you have a collection of Indian states and their capitals. Each state has one and only one capital and a given city can be the capital of only one state. So a hash table goes something like this:

$states = @{"Maharashtra" = "Mumbai"; "Rajasthan" = "Jaipur"; "Andhra Pradesh" = "Hyderabad"}

So the syntax for creating a hash table involves using an at the rate sign (@) followed by a pair of curly braces.
Reply With Quote
  #4  
Old 02-06-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Powershell: declare hash table

A hash table consists of two parts: an array and a mapping function, known as a hash function. The hash function is a mapping from the input space to the integer space that defines the indices of the array. In other words, the hash function provides a way for assigning numbers to the input data such that the data can then be stored at the array index corresponding to the assigned number. A hash function doesn't guarantee that every input will map to a different output. There is always the chance that two inputs will hash to the same output. This indicates that both elements should be inserted at the same place in the array, and this is impossible.

Source: sparknotes
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Powershell: declare hash table"
Thread Thread Starter Forum Replies Last Post
Link a Table to another Table to Drop Down In Main Table himeshRES Windows Software 6 11-12-2010 02:01 PM
What is the Declare Construct in PHP? Rob Dizzle Software Development 5 06-03-2010 03:51 AM
Creating a Hash Table in java Sheenas Software Development 5 19-02-2010 07:24 PM
From Hash Table Remove an Unreferenced Element Level8 Software Development 5 19-02-2010 05:39 PM
Calculating a hash table automatically in SQL Elijah Software Development 4 02-04-2009 11:37 PM


All times are GMT +5.5. The time now is 12:10 PM.