... make use of an iterator or tied array and avoid accumulating, but I would also like to keep the current user interface of simply iteratoring over the results with a for loop. Is this possible?

You could use a tied array in a for loop if the number of items is known in advance (FETCHSIZE is called; see also my reply to the relatively recent thread How can I create an iterator that works inside foreach()). Otherwise I recommend you bite the bullet and switch to while, as that's generally the way to work with iterators in Perl, and iterators are incredibly powerful, as HOP taught us. Such a while can often also be expressed as a C-style for(;;), but IMHO that doesn't always look as elegant as while and foreach.

Update: Another alternative is to provide a custom API for looping with a callback, for example like Mojo::Collection's ->each. I think it would be less performant than a while, though.


In reply to Re: Using lazy list with a for loop (updated) by haukex
in thread Using lazy list with a for loop by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.