Mark Martin wrote:
> Hi,
> okay  - straight out of the coobook :
> 
> my @different = ()
> foreach (keys %hash1)
> {
>    delete $hash1{$_} unless exists $hash2$_};
>    push(@this_not_that,$_) unless exists $registered{$_};
> }
> 
> easy to remove the different key from hash one and record the removed
> item in @different.
> 
> My question is how would you record the removed item in another hash
> so that it has the original key and corresponding value?
> 
> I've tried :
> 
> %different = ();
> foreach $key (keys %hash1)
> {
>    $value = $hash1{$key};
>    @different{$_} = $value unless exists $hash2{$_};
> }

You're using $_, but $key has the key

> 
> but I get all sorts of rubbish

delete() returns the thing(s) deleted, so

    for my $key (keys %hash1) {
        $different{$key} = delete $hash1{$key} unless exists $hash2{$key};
    }

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to