>>> I am sure smarter people can give more technical answers.
Keith Hill is such a guy. I came across a very good explanation of
PowerShell parsing modes and as a sidebar the difference between several
types of expressions!
http://keithhill.spaces.live.com/blo...A97!6058.entry
What's the difference between grouping expressions (), subexpressions $()
and array subexpressions @()? A grouping expression can contain just a
single statement. A subexpression can contain multiple semicolon separated
statements. The output of each statement contributes to the output of the
subexpression. An array subexpression behaves just like a subexpression
except that it guarantees that the output will be an array. The two cases
where this makes a difference are 1) there is no output at all so the result
will be an empy array and 2) the result is a scalar value so the result will
be a single element array containg the scalar value. If the output is
already an array then the use of an array subexpession will have no affect
on the output i.e. array subexpressions do not wrap arrays inside of another
array.
"jas" <james.seatter@xxxxxx> wrote in message
news:CB52EE09-F062-4E6A-8EF9-EA663DF36A36@xxxxxx
Quote:
> Kevin,
>
> Sometimes you need to evaluate an expression and then use the results to
> do something else.
>
> Classicly you would probably do
> $myvar = <some code that returns a value/object>
> if ($mayvar -eq "<somevalue>") { do something else }
>
> Using $() allows you to do this all in one line.
> if($(<some code that returns a value/object>) -eq "<somevalue>") { do
> something else }
>
> You will see this a lot in code as people force an expression to be
> evaluated, you may even see $($myvar) where $myvar is of a type that
> returns an unhelpful object but placing that inside another $() actually
> takes you to the value you want. I am sure smarter people can give more
> technical answers.
>
> James
>
>
> "Kevin Buchan" <kevin.buchan@xxxxxx[Pls Don't Spam]sanders.com> wrote in
> message news
mhoq3t1na8c4rg3gce6vgji0aoeiloqi2@xxxxxx Quote:
>>I have googled and I've used get-help. I've even tried my own tests,
>> but I can't rell what the $() operator does.
>>
>> I've seen it in people's code and I think I can tell, from the
>> context, what it does, but I'm mistaken.
>>
>> #Example 1:
>> param(
>> [string] $wsdlLocation = $(throw "Please specify a WSDL
>> location"),
>> )
>>
>> #Example 2
>> $s = indent "<$($reader.Name) "
>>
>>
>> I was feeling like I was finally nearing the crest of the learning
>> curve, to where I can actually use PowerShell instead of simply
>> running other people's scripts, then I run into this. :-)
>>
>> Thanks!
>>
>> --
>> Kevin Buchan
>> kevin.bucahn@xxxxxx[nospam]sanders.com
>