in reply to Re^2: how to use the values of the first hash to be the keys for the second hash
in thread how to use the values of the first hash to be the keys for the second hash
use feature ":5.14"; use warnings FATAL => qw(all); use strict; use Data::Dump qw(dump pp); my %h1 = (key1=>[qw(1.1.1 1.1.2 1.1.3)], key2=>[qw(1.2.1 1.2.2 1.2.3)] +); my %h2 = (key1=>[qw(2.1.1 2.1.2 2.1.3)], key2=>[qw(2.2.1 2.2.2 2.2.3)] +); my %c; for my $h(\%h1, \%h2) {push @{$c{$_}}, $h->{$_} for keys %$h; } pp(\%c)
Produces:
{ key1 => [["1.1.1", "1.1.2", "1.1.3"], ["2.1.1", "2.1.2", "2.1.3"]], key2 => [["1.2.1", "1.2.2", "1.2.3"], ["2.2.1", "2.2.2", "2.2.3"]], }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: how to use the values of the first hash to be the keys for the second hash
by lrl1997 (Novice) on Sep 07, 2012 at 16:34 UTC |