![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Re: Leading comma operator - What does it do, really? Good question. I'm not aware of any definitive article. An easy way to see the difference: PS>(1,2)|get-member vs PS>,(1,2)|get-member In the first case, each element is passed to get-member. In the second case, the elements remain grouped together and are passed as a whole to get-member. So at first, PowerShell sees the numbers 1 and 2 being passed, while in the second, PowerShell sees a collection of 1 *and* 2 being passed together. That being said, I'm not sure what's going on in your last example below. Marco "Kevin Buchan" <kevin.buchan@newsgroup[PlsDon'tSpam]sanders.com> wrote in message news:n1bva5173gsjipm0gbsdimbiahafkv1q78@newsgroup Quote: > I'm having trouble finding a definitive article on what exactly the > leading comma does. > > PS C:\> $a > PS C:\> $a = 1,2,3 > PS C:\> $b = 4,5,6 > PS C:\> ($a + $b).length > 6 > > It *seems* to treat what follows it as an element in an array, even if > it's an array. So instead of creating a new array with all of the > elements in $a and $b, it creates an array with all of the elements in > $a and another array element with the entire $b array as that single > element. > > PS C:\> ($a + ,$b).length > 4 > PS C:\> > PS C:\> $c = $a + ,$b > PS C:\> $c[3].GetType().FullName > System.Object[] > PS C:\> $c[3] > 4 > 5 > 6 > PS C:\> $c[3][0] > 4 > > When I try it before a string, I get an array with a single element, > the string. > PS C:\> $d = ,"Test","AnotherTest" > PS C:\> $d.GetType().FullName > System.Object[] > PS C:\> $d.length > 2 > PS C:\> $d[0] > Test > > > OK, all of that seems reasonable to me. But, now here's where my mind > gets blown... > > Why, in this example below, is the first element of $e a > multi-dimensional array instead of just being a simple array of > integers? > PS C:\> $e = ,(1,2,3),4,5,6 > PS C:\> $e.length > 4 > PS C:\> $e[0].GetType().FullName > System.Object[] > PS C:\> $e[0][1] # I expected this to return '2'. > PS C:\> $e[0][0] > 1 > 2 > 3 > PS C:\> $e[0][0][1] # What the heck? > 2 > > > -- > Kevin Buchan > kevin.buchan@newsgroup[nospam]sanders.com |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Leading comma operator - What does it do, really? Ditto 'good question'. To paraphrase your example $e = ,(1,2,3),4,5,6 behaves in the same way as $e = ,,(1,2,3) + 4,5,6 whereas one would expect it to be semantically equivalent to $e = ,(1,2,3) + 4,5,6 Possibly a bug ? -- Jon "Kevin Buchan" <kevin.buchan@newsgroup[PlsDon'tSpam]sanders.com> wrote in message news:n1bva5173gsjipm0gbsdimbiahafkv1q78@newsgroup Quote: > I'm having trouble finding a definitive article on what exactly the > leading comma does. > > PS C:\> $a > PS C:\> $a = 1,2,3 > PS C:\> $b = 4,5,6 > PS C:\> ($a + $b).length > 6 > > It *seems* to treat what follows it as an element in an array, even if > it's an array. So instead of creating a new array with all of the > elements in $a and $b, it creates an array with all of the elements in > $a and another array element with the entire $b array as that single > element. > > PS C:\> ($a + ,$b).length > 4 > PS C:\> > PS C:\> $c = $a + ,$b > PS C:\> $c[3].GetType().FullName > System.Object[] > PS C:\> $c[3] > 4 > 5 > 6 > PS C:\> $c[3][0] > 4 > > When I try it before a string, I get an array with a single element, > the string. > PS C:\> $d = ,"Test","AnotherTest" > PS C:\> $d.GetType().FullName > System.Object[] > PS C:\> $d.length > 2 > PS C:\> $d[0] > Test > > > OK, all of that seems reasonable to me. But, now here's where my mind > gets blown... > > Why, in this example below, is the first element of $e a > multi-dimensional array instead of just being a simple array of > integers? > PS C:\> $e = ,(1,2,3),4,5,6 > PS C:\> $e.length > 4 > PS C:\> $e[0].GetType().FullName > System.Object[] > PS C:\> $e[0][1] # I expected this to return '2'. > PS C:\> $e[0][0] > 1 > 2 > 3 > PS C:\> $e[0][0][1] # What the heck? > 2 > > > -- > Kevin Buchan > kevin.buchan@newsgroup[nospam]sanders.com |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Leading comma operator - What does it do, really? PS C:\> $e.SyncRoot helps illuminate the structure of $e Try, for example PS C:> $e = ,(1,2),,(3,4),,(5,6) PS C:> $e.SyncRoot See also http://devcentral.f5.com/weblogs/Joe...nraveling.aspx - Larry Kevin Buchan wrote: Quote: > ... > Why, in this example below, is the first element of $e a > multi-dimensional array instead of just being a simple array of > integers? > PS C:\> $e = ,(1,2,3),4,5,6 > PS C:\> $e.length > 4 > PS C:\> $e[0].GetType().FullName > System.Object[] > PS C:\> $e[0][1] # I expected this to return '2'. > PS C:\> $e[0][0] > 1 > 2 > 3 > PS C:\> $e[0][0][1] # What the heck? > 2 > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Leading comma operator - What does it do, really? PS C:> $e = ,(1,2),,(3,4),,(5,6) can be written as PS C:> $e = (,(1,2)),(,(3,4)),(,(5,6)) - Larry Larry__Weiss wrote: Quote: > PS C:\> $e.SyncRoot > > helps illuminate the structure of $e > Try, for example > > PS C:> $e = ,(1,2),,(3,4),,(5,6) > PS C:> $e.SyncRoot > > See also > http://devcentral.f5.com/weblogs/Joe...nraveling.aspx > > Kevin Buchan wrote: Quote: > > ... >> Why, in this example below, is the first element of $e a >> multi-dimensional array instead of just being a simple array of >> integers? >> PS C:\> $e = ,(1,2,3),4,5,6 >> PS C:\> $e.length >> 4 >> PS C:\> $e[0].GetType().FullName >> System.Object[] >> PS C:\> $e[0][1] # I expected this to return '2'. >> PS C:\> $e[0][0] >> 1 >> 2 >> 3 >> PS C:\> $e[0][0][1] # What the heck? >> 2 >> |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| comma delimited text file into database | PowerShell | |||
| Search fails if Folder name has comma in it? | Vista file management | |||
| do something for each token in a line separated by comma | PowerShell | |||
| Escape comma in dos command from PS script | PowerShell | |||
| Leading Mattress-Maker Spring Air to Rest Easier With Microsoft Dynamics AX Technology Solution | Vista News | |||