We don't bite newbies here... much | |
PerlMonks |
Re^9: Getting for() to accept a tied array in one statementby ikegami (Patriarch) |
on Apr 22, 2019 at 21:56 UTC ( [id://1232883]=note: print w/replies, xml ) | Need Help?? |
I presume Python's has native support for iterators. Perl 6 has lazy lists, but Perl 5's doesn't, and nothing's going to make for work with lazy lists short of overriding for/foreach. Tied arrays definitely can't achieve that. There are a few modules that provide iterator-aware looping primitives. Search for "iterator" on CPAN.
That's not true. Whether it's called for every loop pass or not, it's still called before the first pass, so you still need to know the size up front. And FETCHSIZE must always return a correct value because it's called once in other situations. In fact, I consider it a bug that FETCHSIZE is called more than once in that situation. Ironically, if you circumvent the optimisation of for (@a) by using for ((), @a), you actually get something faster for tied arrays since the latter only calls FETCHSIZE once.
In Section
Seekers of Perl Wisdom
|
|