Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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 making s'mores by the fire in the courtyard of the Monastery: (13)
As of 2015-07-06 16:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (77 votes), past polls