Looking through the code, the author states:

From _initialize (called from new):
# Caches the first value of the iterator in %next_value +_for.
and value:
# Notes: Keeps one forward-looking value for the iterator +in # %next_value_for. This is so we have something + to # return when user's code throws Am_Now_Exhauste +d.
Assuming this is to know when the iterator will be exhausted, as pKai said.

For your second example, this is explicitly stated in the docs:
When you use an iterator in separate parts of your program, or as an a +rgument to the various iterator functions, you do not get a copy of t +he iterator's stream of values. In other words, if you grab a value from an iterator, then some other +part of the program grabs a value from the same iterator, you will be + getting different values. This can be confusing if you're not expecting it. For example: my $it_one = Iterator->new ({something}); my $it_two = some_iterator_transformation $it_one; my $value = $it_two->value(); my $whoops = $it_one->value; Here, some_iterator_transformation takes an iterator as an argument, a +nd returns an iterator as a result. When a value is fetched from $it_ +two, it internally grabs a value from $it_one (and presumably transfo +rms it somehow). If you then grab a value from $it_one, you'll get it +s second value (or third, or whatever, depending on how many values $ +it_two grabbed), not the first.
IMO, if you needed to use the value returned from the iterator, save it somewhere instead of using a variable in the same scope - although I realize that your code is more than likely a simplification of what you're really trying to do

In reply to Re: Any thoughs on Iterator prefetching? by Transient
in thread Any thoughs on Iterator prefetching? by mzedeler

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.