in reply to Re^6: Sub-setting an Array
in thread Sub-setting an Array
Well, how would you say that in English?
Something like "Stop if the difference between the position of the element we're on and the length of the array is smaller than the length of the window we want", right? So in Perl that might be as simple as:
Which will stop the whole loop as soon as it's true. Add it after the next statement and see what happens.last if $elements - $offset < 3;
Edit: If you are really wanting to get a sliding subset of the array, you wouldn't want to use splice since as you can see it changes the original array and soon you have no elements left! But making a copy of the array each time through a loop, as I did in the example, is horribly inefficient, and the example is only designed to explain the use of splice, which is what the OP asked for ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Sub-setting an Array
by kgherman (Novice) on Sep 05, 2015 at 01:33 UTC | |
|
Re^8: Sub-setting an Array (sliding window is fifo/queue...?)
by Anonymous Monk on Sep 05, 2015 at 02:27 UTC |