in reply to Re: What is the easiest way to merge two hashes?
in thread What is the easiest way to merge two hashes?
Outputs:use Data::Dumper; my $hash1 = { common_key => 'foo', hash1_specific_key => 'some value' }; my $hash2 = { common_key => 'bar', hash2_specific_key => 'some other value' }; my $joined_keys = [ keys( %{ { map { $_=>undef } keys( %{$hash1} ) , keys( %{$hash2} ) } } ) ]; print Data::Dumper->Dump([$joined_keys],['joined keys']);
$joined keys = [ 'hash2_specific_key', 'common_key', 'hash1_specific_key' ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: What is the easiest way to merge two hashes?
by BrowserUk (Patriarch) on Feb 15, 2015 at 11:14 UTC | |
by tkguifan (Scribe) on Feb 15, 2015 at 14:30 UTC | |
by BrowserUk (Patriarch) on Feb 15, 2015 at 16:37 UTC |