This and other RFCs are available on the web at http://dev.perl.org/rfc/ =head1 TITLE Fix iteration of nested hashes =head1 VERSION Maintainer: Damian Conway <[EMAIL PROTECTED]> Date: 18 Sep 2000 Mailing List: [EMAIL PROTECTED] Number: 255 Version: 1 Status: Developing =head1 ABSTRACT This RFC proposes that the internal cursor iterated by the C<each> function be attached to the instance of C<each> (i.e. its op-tree node), rather than the hash being iterated. =head1 DESCRIPTION Currently, nesting two C<each> iterations on the same hash leads to unexpected behaviour, because both C<each>s advance the same internal cursor within the hash. For example: %desc = ( blue => "moon", green => "egg", red => "Baron" ); while ( my ($key1,$value1) = each %desc ) { while ( my ($key2,$value2) = each %desc ) { print "$value2 is not $key1\n" unless $key1 eq $key2; } } print "(finished)\n"; It is proposed that each C<each> maintain its own cursor (within its compiled op-tree node), so that the above example DWIMs. =head1 MIGRATION ISSUES Minimal. No-one nests iterators now because it doesn't work. Would not (necessarily) have an effect on the use of FIRSTKEY and NEXTkey in tied hashes, since the compiler could still determine which should be called. However, tied hashes that use an internal cursor might behave differently, if nested. =head1 IMPLEMENTATION Attach the cursor to the op-tree node, rather than the hash. =head1 REFERENCES RFC 136: (Implementation of hash iterators) suggests separate iterators for C<each> and C<keys>/C<values>.