Re: FAQ 4.57 What happens if I add or remove keys from a hash while iterating over it?



Uri Guttman wrote:
"EP" == Eric Pozharski <whynot@xxxxxxxxxxxxxx> writes:

EP> $h{$_} = $_ foreach 0 .. 1E4;

since i like slices:

%h{ 0 .. 1e4 } = 0 .. 1E4 ;

ITYM:

@h{ 0 .. 1e4 } = 0 .. 1E4 ;


EP> while( $x = each %h ) {
EP> EP> delete $h{$x + 1};
EP> push @z, $x + 1;

and very few seem to know that delete returns its value and since your
keys and values are the same:

push @z, delete $h{$x + 1} ;

:)


John
--
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
.