in reply to Delete keys in hash if they exist in another hash

I may be misunderstanding you, but I think you just want:

delete @hash{keys %end};

Here's a simple program that demonstrates it:

#!/usr/bin/perl use strict; use warnings; my %hash = (one => 1, two => 2, three => 3); my %end = (two => 2); delete @hash{keys %end}; print "$_ => $hash{$_}\n" for keys %hash;

By the way, I've taken my specification from your post where you say "delete the keys in %hash if they exist in %end", rather than your code which seems to do the opposite.

--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: Delete keys in hash if they exist in another hash
by tgolf4fun (Novice) on Nov 13, 2004 at 00:23 UTC
    Your code showed me what I was doing wrong. I've fixed this and my script works fine now. I kept skipping past the section on hash slices, now I know I should have stopped to read it. Your print command was also a big help. Thanks for your wisedom and patience for a newbie trying to make it up the ranks. :-)