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

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

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995644]
[davido]: If you ever doubt the progress made in CPU technology: I have a script that runs in 2m20s on a Core2-Duo with 8GB RAM and an SSD. On an i7-2700K, also with SSD, same script runs in 12.5s.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2017-11-22 15:06 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (326 votes). Check out past polls.