Yes, this is a little bit unfortunate.
But there is a quick fix:
$maybeEmpty = @( @() | % { $_ } )
so
@( @() | % { $_ } ).Length -eq 0
On May 21, 12:35*pm, DioGenus <DioGe...@newsgroup>
wrote:
> I would intuitively think that since the output from a pipeline normally is
> an array, the "output" from an empty pipeline should be the empty array @().
>
> E.g.
>
> * * PS> ( @(1,2) | % { $_ } ).GetType()
>
> * * IsPublic IsSerial Name * * * * * * * * * * * * * * * * * * BaseType
> * * -------- -------- ---- * * * * * * * * * * * * * * * * * * --------
> * * True * * True * * Object[] * * * * * * * * * * * * * * * * System.Array
>
> is an array while
>
> * * PS> ( @() | % { $_ } ) -eq $null
> * * True
>
> Can anyone explain why $null is a better choice than @()? *In my scripts, I
> now have to perform extra testing before I can add the output of a pipeline
> to an existing array since the following statement would just add *a $null
> element to $myArray if $maybeEmptyArray is empty:
>
> * * $myArray += @() + $maybeEmptyArray | % { doProcess $_ }
>
> I obviously want nothing added to $myArray if $maybeEmptyArray is empty.