On Tue, 19 Sep 2000, Tom Christiansen wrote:
> >This RFC proposes that the internal cursor iterated by the C<each> function 
> >be stored in the pad of the block containing the C<each>, rather than
> >being stored within the hash being iterated.
> 
> Then how do you specify which iterator is to be reset when you wish 
> to do that?  Currently, you do this by specifying the hash.  If the

Suppose we change each to be:
        each HASH
        each ITERATOR
and create a new keyword,
        iterator HASH 
which creates a new iterator for the specified hash.  This iterator can
then be eached, just like the hash, and reset using
        reset ITERATOR

Usage would then look like this (stealing Damian's code):

%desc = ( blue  => "moon",
          green => "egg",
          red   => "Baron" );

$i1 = iterator %desc;
$i2 = iterator %desc;
while ( my ($key1,$value1) = each $i1)
{
      while ( my ($key2,$value2) = each $i2 )
      {
             print "$value2 is not $key1\n" unless $key1 eq $key2;
      }
}
print "(finished)\n";


This runs into problems if you currently have an iterator extant and you
modify the hash to which it points.  Immediate suggestions on how to
handle this would be:

        1) Do what the docs currently do; tell people "don't do that"
        2) Have the iterator auto-reset when the hash is modified
(probably bad)
        3) Make the hash unmodifiable while there is an iterator extant
(probably bad)
        4) Make powerful magic in some way that isn't coming to mind


                                Dave

Reply via email to