i tried the above too, and like
antirice was also puzzled.
however, my perl, 5.8.0, i586 linux, does not die.
i think the oddities manifest are the result of possibly undefined
behaviour when dealing with previously 'deleted' elements on
treating the hash as a list. here is a brief pseudoexplanation:
what happens is the following:
taking
1: foreach my $key (%hash) {
2: print $key;
3: delete $hash{$key};
4: }
as an example:
the first iteration takes a real key, and deletes (line 3) it as if
deleting from a hash. the effect of this is to nullify the value
associated with the real key.
when we go to the next iteration, which is done over a *list*, because (camel book) 'modification
to (foreach) loop values can change the original values', we end up
having undef as an iterator value. ie the ghost of the previously deleted key.
this undef value remains in the foreach iterator's
conception of the hash - presumably because it thinks of the hash
as a list. so on next iteration, line 2 attempts to print an undef value,
and line 3 attempts to delete it, which has no effect on the actual
keys still in the hash.
you can test this by including a
print join ":", keys %hash after line 3.
next rinse, we delete a 'real' key from the hash again, and then
attempt to iterate on what has become an undefined value.
so we go through a "delete real key from hash, delete undef from hash" cycle, thanks to our iteration which treats the hash as a list.
i guess what i am a little surprised about is that those undef values
still remain in the concept of the list as seen by foreach. i guess this
is a byproduct of treating the hash as a list, and forcing a peek at
the phantom value.
i would be interested if anyone could confirm/deny this was indeed happening.but more, if some kind soul would give an explanation of why the third
antirice loop works, i could sleep easy. easier...
wufnik
-- in the world of the mules there are no rules --