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
#!/usr/bin/perl use warnings; use strict; my %hash1 = (key1 => [qw(val1 val2)], key2 => ['val3'], ); my %hash2 = (val1 => [qw(val5 val6 val7)], val2 => [qw(val8 val9)], val3 => ['val3'], ); my %result = (map { $_ => [ map @{ $hash2{$_} } , @{ $hash1{$_} } ] } keys %hash1); while (my ($k, $v) = each %result) { print $k, " @$v\n"; }
|
|---|
| 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 19:16 UTC | |
by choroba (Cardinal) on Sep 07, 2012 at 23:21 UTC |