While reading Powershell in Action, I got stuck on a passage in Chapter 5. I follow the result here, but could someone explain the purpose and the reason behind it?
$nested = 4, (5, 6)
$flattened = $nested | foreach { $_ }
$flattened.length
That gives $flattened.length as 3. Fair enough.
$nested = 4, (5, 6)
$flattened = $nested | foreach { ,$_ }
$flattened.length
This time $flattened.length gives 2.
Running $flattened[0]; $flattened[1] -join "," explains those 2 objects, but what precisely does the comma inside that second ForEach accomplish?
Does it mean, roughly, “Keep 4 as an object and (5,6) as its seperate object. Leave them intact.”