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;
|
|---|
| 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 |