Hi Alex, On Sun, 9 Mar 2014 16:40:54 +1100 Alex Chiang <s3442...@student.rmit.edu.au> wrote:
> Hi all, > > I'm a perl beginner, and when I tries to practice delete built-in, I find > it's not working as I supposed to. > > 44 my %employ_list = ("e10220" => "Du", "e10250" => "Vic"); > 45 # iterate thru with each > 46 while ( my ($k, $v) = each %employ_list ) { > 47 print " before: key:$k => value:$v \n"; > 48 if ($k eq "e10220") { delete $employ_list{$k}; } In addition to what Uri said, you should not delete a key out of a hash (or add keys) while iterating over it using each(), because this may confuse Perl: http://perl-begin.org/tutorials/bad-elements/#modifying_iterated_array (Note: http://perl-begin.org/ is a site I originated and maintain). Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ My Aphorisms - http://www.shlomifish.org/humour.html There is no IGLU cabal! The former cabalists are trying to prove the correctness of a program that proves the correctness of proofs of other programs. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/