![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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: String values in variables -- SOLVED Michael Powe wrote: Quote: > Okay, I'm an idiot. The problem was in the function call. I forgot > that you call the function without parens (like calling a sub in VB). > Once I fixed the function call, I fixed my problem. > parenthesis around the set of function parameters separated my commas leads us to expect to carry forward that pattern into the calls. It is just plain inconsistent. function subtract($from, $count) { $from - $count } and the call is subtract 5 4 Even the alternative of function subtract { param($from, $count) $from - $count } uses a pattern involving parenthesis and commas. And further confusing is that when you invoke .NET methods, you use the more traditional form of passing arguments. Once you get used to it, it does have the benefit of distinguishing the PowerShell function and command calls from the calls to the .NET methods. For example, subtract "0123456789".IndexOf("5",0) "0123456789".IndexOf("4",0) (making up a contrived example). - Larry |
My System Specs![]() |
| | #2 (permalink) |
| | Re: String values in variables -- SOLVED In message <ukMTtzkWKHA.2008@newsgroup>, Larry__Weiss <lfw@newsgroup> writes Quote: >PowerShell's design of how you can specify a formal parameters, by >using parenthesis around the set of function parameters separated my >commas leads us to expect to carry forward that pattern into the calls. we didn't - and I suspect we'll have to live with his feature. -- Thomas Lee doctordns@newsgroup |
My System Specs![]() |
| | #3 (permalink) |
| | Re: String values in variables -- SOLVED Thomas Lee wrote: Quote: > In message <ukMTtzkWKHA.2008@newsgroup>, Larry__Weiss > <lfw@newsgroup> writes Quote: >> PowerShell's design of how you can specify a formal parameters, by >> using parenthesis around the set of function parameters separated my >> commas leads us to expect to carry forward that pattern into the calls. > With the benefit of hindsight, I wished we'd had parens and commas. But > we didn't - and I suspect we'll have to live with his feature. alone, is to better follow in the traditions of a command line language, while allowing PowerShell to have a consistent syntax for both command line and scripting. In truth, you don't have to use a space as a delimiter. Consider: PS C:> function add {param($a1,$a2) $a1+$a2} PS C:> add (1)(2) 3 You just have to "finish" one parameter value and then you can begin the next. A space character is just the usual way to show a parameter value is completely specified. A comma never finishes a parameter value as it just indicates that the value is to be wrapped as an array. Consider: PS C:> function addlen {param($a1,$a2) $a1.length+$a2.length} PS C:> addlen 1 1,2 2 PS C:> addlen 1,2,3 1,2 5 PS C:> addlen (1,2,3)(1,2) 5 PS C:> addlen (1,2,3),(1,2) 2 PS C:> addlen (1,2,3),(1,2) 1,2,3,4,5,6,7,8,9,10 12 - Larry |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Using @ Sign at String Variables? | .NET General | |||
| Capture elements of a string into variables | VB Script | |||
| Re: best way to break string into variables | PowerShell | |||
| Re: gwmi values into variables | PowerShell | |||
| Shortening string values | PowerShell | |||