Allow the .. Operator to Accept a Step Value and a Keyword to Signify the Array's length
Votes from Connect: 10
Original Date Submitted: 3/8/2012 8:34:09 AM
Site Name: PowerShell
Feedback ID: 729570
Frequency: Always Happens
Regression: Yes, this happens in all previous versions
In other scripting languages such as Python and MatLab, you can create say a list of all numbers from 0 to 100 stepping by 5 each time by typing something like 0:5:100. Also, you can splice an array from a point to the end by typing 0:end or in Python the last item is -1. In Powershell the .. operator can only accept a starting and an ending value but from what I know not a stepping value and not a keyword to tell it to find the end of ann array but you have to use the more wordy .length notation instead. So, for example I can't get all the even lines from a file by typing $l = cat file.txt; $f[0..2..end]; for example. I have to write a for loop instead. Please, since you have the .. operator, do not let it stand there without being used. Just add these two little things to it and it could eliminate the usage of so many loops. Otherwise, the .. operator is very limited unlike most other scripting languages.
Product Studio item created by Connect Synchronizer due to creation of feedback ID 729570 (http://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=729570).
Type 1..2..9; notice that you get an error.
A) When I type 0..5..100 I want to get an array of all the numbers from 0 to 100 stepping by 5 each time, i.e. 0, 5, 10, 15, ..., 90, 95, 100.
B) When I type $arr[5..2..end] I want to be able to get all the even elements of the array $arr from element 5 to ($arr.length - 1).
Internal BugId: 3419