in reply to merging two hashes and updating the 1st hash keys.

Another way of doing it.
#!/usr/bin/perl use strict; my %hash_1 = ( 'a' => 'b', 'c' => 'd', 'e' => 'f' ); my %hash_2 = ( 'a' => 'J', 'e' => 'K' ); my %new_hash; $new_hash{$_} = $hash_2{$_} ? $hash_2{$_} : $hash_1{$_} for keys %hash_1; print map { $_ => " => " . $new_hash{$_} . "\n" } keys %new_hash;

Replies are listed 'Best First'.
Re^2: merging two hashes and updating the 1st hash keys.
by sathiya.sw (Monk) on Aug 28, 2009 at 07:10 UTC
    Yeah this way works !! But as i told in the question, i dont want to iterate over each hash element and am looking for a smarter way ! Anyway thanks for your response..
    Sathiyamoorthy