Use the delete function to remove an element from a hash. Example: delete $hash{foo};
If you only want to remove one of the elements from the anonymous array (say the second element) in the hash element 'foo', you can do this: delete $hash{foo}[1];
BTW, to keep the values of the hash that you're deleting (in the %wanted hash), the delete function returns the key and value. Example: $wanted{foo} = delete $hash{foo};
Here's a complete example:
my %wanted = ();
my %hash = ( 'foo' => [1,2,3], 'bar' =>[3,4,5]);
$wanted{foo} = delete $hash{foo};
print "Left-over:\n";
for $key (keys %hash) {
print "$key, @{$hash{$key}}\n";
}
print "Wanted:\n";
for $key (keys %wanted) {
print "$key, @{$wanted{$key}}\n";
}
Produces the following output:
Left-over:
bar, 3 4 5
Wanted:
foo, 1 2 3
Good luck!
|