Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Merge 2 hashes which contains duplicate Keys

by 2teez (Priest)
on Sep 25, 2012 at 22:51 UTC ( #995644=note: print w/ replies, xml ) Need Help??


in reply to Merge 2 hashes which contains duplicate Keys

You might also find the following useful:

use warnings; use strict; use Data::Dumper; my %h1 = ( "one" => 1, "two" => 2, "three" => 3, ); my %h2 = ( "four" => 4, "five" => 5, "six" => 6, "one" => 11111, ); my $grand_hash_ref = {}; foreach my $hash_ref ( \( %h1, %h2 ) ) { while ( my ( $key, $value ) = each %{$hash_ref} ) { push @{ $grand_hash_ref->{$key} }, $value; } } print Dumper $grand_hash_ref;

Please, check perldsc for detailed information.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re: Merge 2 hashes which contains duplicate Keys
Download Code
Re^2: Merge 2 hashes which contains duplicate Keys
by slayedbylucifer (Scribe) on Sep 26, 2012 at 04:41 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995644]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (13)
As of 2014-07-23 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (139 votes), past polls