Pages

3/19/2011

Hash of Arrays

Advanced data structures are sometimes so complicated that I have no use for them. However I have found that a hash of arrays is very useful. Gathering data into the structure and retrieving it is elegant and saves a lot of strange contortions using variables just for looping and incrementing an index/etc. (For example, for each mailbox in a list write $alias[$mailbox]. Or just $alias['JimBob']...)
However, moving from Perl to Powershell I found myself having to re-learn how to make them work.
The following junk helped me to experimentally muddle through the process in PowerShell:
$List = 'User1','User2'
$MBX = 'Box1','Box2'
$MBX += 'Box2'
#$prm=@{$MBX=$List}
$prm=@{$MBX[1]='User1','User2'}
$prm.($MBX[1])+='User3'
$prm
write " "
$MBX = $MBX | Select -Unique
$MBX

No comments: