I'm trying to understand array unrolling in Posh and the following puzzles me. In this example I return the array wrapped in another array (using a comma), which basically gives me the original array after the outer array gets unrolled on return. Why then do I get a correct result (just the array) when I indirectly wrap the result by using the array operator (@) on a variable with the result, but get an array in an array if I use @ directly on the function? Does @ operator behave differently for different types of its parameter? Is there any PS help article for the @ operator and the array unrolling?
function Unroll
{
return ,@(1,2,3)
}
Write-Host "No wrapper"
$noWrapper = Unroll #This is array[3]
$noWrapper | % { $_.GetType() }
Write-Host "`nWrapped separately"
$arrayWrapper = @($noWrapper) #No change, still array[3]
$arrayWrapper | % { $_.GetType() }
Write-Host "`nWrapped directly"
$directArrayWrapper = @(Unroll) #Why is this array[1][3] then?
$directArrayWrapper | % { $_.GetType() }
Write-Host "`nThe original array in elem 0"
$directArrayWrapper[0] | % { $_.GetType() }
Thanks