Re: FAQ 4.57 What happens if I add or remove keys from a hash while iterating over it?
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Sat, 04 Jul 2009 16:30:09 -0700
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
.
- Follow-Ups:
- References:
- FAQ 4.57 What happens if I add or remove keys from a hash while iterating over it?
- From: PerlFAQ Server
- Re: FAQ 4.57 What happens if I add or remove keys from a hash while iterating over it?
- From: Ben Morrow
- Re: FAQ 4.57 What happens if I add or remove keys from a hash while iterating over it?
- From: brian d foy
- Re: FAQ 4.57 What happens if I add or remove keys from a hash while iterating over it?
- From: Eric Pozharski
- Re: FAQ 4.57 What happens if I add or remove keys from a hash while iterating over it?
- From: Uri Guttman
- FAQ 4.57 What happens if I add or remove keys from a hash while iterating over it?
- Prev by Date: Re: FAQ 4.57 What happens if I add or remove keys from a hash while iterating over it?
- Next by Date: Re: FAQ 4.57 What happens if I add or remove keys from a hash while iterating over it?
- Previous by thread: Re: FAQ 4.57 What happens if I add or remove keys from a hash while iterating over it?
- Next by thread: Re: FAQ 4.57 What happens if I add or remove keys from a hash while iterating over it?
- Index(es):