in reply to Re^9: Getting for() to accept a tied array in one statement
in thread Getting for() to accept a tied array in one statement
But isn't the fact that FETCHSIZE is called "more than once" (a.k.a. once per iteration) is how we achieve "don't have to calculate the length of the list in advance?". The first call to FETCHSIZE, we fetch from the iterator. If there is no item, we return 0, ending the for(). If there is an item, we return 1 and push() the fetched item in a buffer, and for() continue. In the next iteration, FETCHSIZE is called again. We fetch from the iterator. If there is no item, we still return 1, ending the for(). If there is still an item, we return 1+1=2 and push() the item in a buffer.
FETCH will shift() item from buffer.
Where do we calculate the length of the list in advance?
Range::ArrayIter is a proof of concept of range iterator using tied array. You can use range_iter(1, Inf), for example. Yes, it's slower than object-based and coderef-based iterator.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^11: Getting for() to accept a tied array in one statement
by ikegami (Patriarch) on Apr 24, 2019 at 15:13 UTC | |
by perlancar (Hermit) on Apr 25, 2019 at 05:37 UTC | |
by ikegami (Patriarch) on Apr 25, 2019 at 17:24 UTC | |
by perlancar (Hermit) on Apr 26, 2019 at 03:00 UTC | |
by ikegami (Patriarch) on Apr 28, 2019 at 19:13 UTC |