<p>Has anybody found a good solution for lazily-evaluated lists in Perl? I've tried a number of ways to turn something like  </p>

<pre><code>for my $item ( map { ... } @list ) { 
}
</code></pre>

<p>into a lazy evaluation--by tie-ing @list, for example. I'm trying to avoid breaking down and writing a source filter to do it, because they mess with your ability to debug the code. Has anybody had any success. Or do you just have to break down and use a while loop? </p>

<p><strong>Note:</strong> I guess that I should mention that I'm kind of hooked on sometimes long grep-map chains for functionally transforming lists. So it's not so much the foreach loop or the while loop. It's that map expressions tend to pack more functionality into the same vertical space. </p>

If I remember correctly, for/foreach do get the whole list first anyways, so a lazily evaluated list would be read completely and then it would start to iterate through the elements. Therefore, I think there's no other way than using a while loop. But I may be wrong.
The advantage of a while loop is that you can fake the sensation of a lazily evaluated list with a code reference:
```
```
my $list = sub { return calculate_next_element };
while(defined(my $element = &$list)) {
    ...
}
```
```
After all, I guess a tie is as close as you can get in Perl 5.