in reply to Re: Re: Hashes: Deleting elements while iterating
in thread Hashes: Deleting elements while iterating

Put in a print statement in the "faulty" for-loop and you'll see immediately what goes wrong.

foreach $key (%index){ print "deleting $key\n"; # delete $index{$key} if ($key =~ /$test.+/); }

Hope this helps, -gjb-

Replies are listed 'Best First'.
Re: Re: Re: Re: Hashes: Deleting elements while iterating
by knexus (Hermit) on Sep 02, 2003 at 21:20 UTC
    Yes, indeed it does help. Thanks.

    So, after digging more in my book, I see now that i needed a keys function in it. All is well again.

    foreach $key (keys %index) { print "deleting $key\n"; # delete $index{$key} if ($key =~ /$test.+/); }

    Some of us just need learn the hard way!

    Update: I see now an earlier reply by chromatic, mentioned needing the keys function as well, but it was lost on me at that moment. Sorry.