My perl (AS 5.61 on Windows XP) also dies, but not every time. Using diagnostics, I get the following message, among others:
Attempt to free unreferenced scalar at scratchpad2.pl line 5 (#2): (W internal) Perl went to decrement the reference count of a scalar to see if it would go to 0, and discovered that it had already gone to 0 earlier, and should have been freed, and in fact, probably was freed. This could indicate that SvREFCNT_dec() was called too many times, or that SvREFCNT_inc() was called too few times, or that the SV was mortalized when it shouldn't have been, or that memory has been corrupted.
which may help some, but I'm afraid is a little over my head.
Concerning the third antirice loop:
I thought it looked to be (conceptually) equivalent to something like:foreach my $key ( @{[%hash]} ) { # print "$key: @{[%hash]}\n"; delete $hash{$key}; }
foreach my $key (my @ary = %hash) { # print "$key: @ary\n"; delete $hash{$key}; }
(which also 'works', BTW), but apparently it isn't the same, since uncommenting the print lines shows that the anonymous array reference (vocab a bit shaky here...) [%hash] shrinks by two items with each iteration, while the 'straight' array @ary remains unchanged.
Oh dear, not sure if all that helps at all...
dave
In reply to Re: Re: Re: Hashes: Deleting elements while iterating - deleting phantoms?
by Not_a_Number
in thread Hashes: Deleting elements while iterating
by knexus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |