On Apr 12, 7:46*pm, RichS [MVP] <RichS...@xxxxxx>
wrote:
| Quote: |  | |
|
> In certain circumstances I can see that this would\could be useful but the
> overhead of maintaining it I think is too high. *It would also mean thateach
> step in the pipeline had to complete its processing before passing data along
> otherwise subsequent cmdlets wouldn't have an accurate count. *This could be
> a severe performance hit
> --
| |
| | |
Sorry Rich, I didn't explain my suggestion adequately.
A single integer, incremented once each time that ProcessRecord is
called, would not be a performance hit of any significance at all.
I guess the obvious implemetation would be to make this integer a
member of the Cmdlet class (although implementing it in the same may
as $_ would also be appropraite).
And much like $_, this proposed variable would only exist in the
context of the current pipeline step. It would not imply that any
other processing needs to complete as you suggested. And since it
only exists in the context of the current command, it wouldn't get
passed on to subsequent cmdlets, so there's no overhead there either.
To illustrate... if this counter were accessible as $%, then....
dir | % { $%, Name }
would emit...
0
bin
1
cygwin
2
dell
3
Dev
4
dir | ? { [int](%_/2) -eq ($%/2) }
would emit every alternate record
(These examples are meant to show behaviour, not usefullness)
Michael