sathiya.sw has asked for the wisdom of the Perl Monks concerning the following question:
Output should be like...%hash1 = ( a, b, c, d, e, f ); %hash2 = ( a, J, e, K ); use Data::Dumper; print Dumper ( \%hash1 ); print Dumper ( \%hash2 ); # WHAT TO DO HERE TO GET UPDATED VALUES ?? print "=========AFTER===========\n"; print Dumper ( \%hash1 ); #print Dumper ( \%hash2 );
I had the following ways of doing it...$VAR1 = { 'e' => 'f', 'c' => 'd', 'a' => 'b' }; $VAR1 = { 'e' => 'K', 'a' => 'J' }; =========AFTER=========== $VAR1 = { 'e' => 'K', 'c' => 'd', 'a' => 'J' };
%hash1 = ( %hash1, %hash2 );
The first way seems promising as i have the requirement of only the first hash keys remain as it is, where as the 2nd way shown here will put the 2nd hash sets unique keys also into the 1st hash.
Question is
I would not want to run over all the hash keys and then do this operation ?! Do you have any single liner, or some statement which can do this operation smarter ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: merging two hashes and updating the 1st hash keys.
by moritz (Cardinal) on Aug 27, 2009 at 11:29 UTC | |
|
Re: merging two hashes and updating the 1st hash keys.
by roboticus (Chancellor) on Aug 27, 2009 at 12:29 UTC | |
by GrandFather (Saint) on Aug 27, 2009 at 20:52 UTC | |
|
Re: merging two hashes and updating the 1st hash keys.
by Anonymous Monk on Aug 27, 2009 at 11:35 UTC | |
by sathiya.sw (Monk) on Aug 28, 2009 at 06:59 UTC | |
|
Re: merging two hashes and updating the 1st hash keys.
by BrowserUk (Patriarch) on Aug 28, 2009 at 07:21 UTC | |
|
Re: merging two hashes and updating the 1st hash keys.
by bichonfrise74 (Vicar) on Aug 27, 2009 at 22:04 UTC | |
by sathiya.sw (Monk) on Aug 28, 2009 at 07:10 UTC |