This behavior isn't that suprising if you remember that each isn't returning you an iterator which is magically affected by the operations on previously used iterators -- or can magically affect subsequent iterators.
each is advancing the existing iterator contained in the internals of the hash you are working with -- that iterator is shared by everyone who has a refrence to that hash, in the same way the data inside the hash is shared by everyone with a refrence to it.
Put another way: If perl looked more like java, then i'd agree with you that this is a bug...
my $iter = %data.iter; while (my ($key, $val) = each($iter)) { last if ($key eq 'drop_out'); print("$key => $val\n"); }
...but as it stands, this behavior is no more suprising to me then if you were looping over the keys to a hash, and modifying the values -- and then outside of the loop you discovered that the hash had been changed.
In reply to Re: The Anomalous each()
by hossman
in thread The Anomalous each()
by jdhedden
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |