Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Merge 2 hashes which contains duplicate Keys

by 2teez (Vicar)
on Sep 25, 2012 at 22:51 UTC ( [id://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

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://995644]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-19 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found