note
TimToady
This particular problem is solved in Perl 6 by always cloning all blocks as closures the same way, so <tt>state</tt> is reset in loops as well as in <tt>map</tt>. (In fact, the <tt>for</tt> loop is defined in terms of <tt>map</tt> in Perl 6. So <tt>for</tt> loops return a list of values just like <tt>map</tt> does.) Perl 5 could probably move in the direction of fewer special-cased blocks that aren't true closures; this would have many subtle benefits. Not everything in Perl 6 can be borrowed back, but I suspect this is one of them.
880228
880240