in reply to Re: how can i replace a hash key with other hash value?
in thread how can i replace a hash key with other hash value?

You can't "replace a key" but you can set a new one and delete the existing one
And you can do that in one line:
$hash{$hash_tr_fr{$eng}} = delete $hash{$eng};
which has the added benefit to even work correctly when $hash_tr_fr{$eng} eq $eng. Doing the delete in a separate step would result in a loss of the entry.

Replies are listed 'Best First'.
Re^3: how can i replace a hash key with other hash value?
by cdarke (Prior) on Mar 24, 2010 at 10:59 UTC
    ...or even in a slice without the loop. So:
    for my $eng (keys %hash){ $hash{$hash_tr_fr{$eng}}=$hash{$eng}; delete $hash{$eng}; }
    becomes:
    my @temp = keys %hash; @hash{@hash_tr_fr{@temp}} = delete @hash{@temp};
    Update: corrected missing @, thanks SuicideJunkie