in reply to Combining two hashes

Hi,
Just in case, if in each of the two hashes you happen to have two same keys (in example here they are "key1") with different value, and you want to keep them. This could be the way to do it:
#!/usr/bin/perl -w use strict; use Data::Dumper; my %hash1 = ('key1' => 'val1', 'key2' => 'val9'); my %hash2 = ('key3' => 'val10','key1' => 'val2'); while (my ($key, $val) = each %hash1) { $hash1{$key} = [$val]; } while (my ($key, $val) = each %hash2) { push @{$hash1{$key}}, $hash2{$key}; } print Dumper \%hash1;
Prints:
$VAR1 = { 'key2' => [ 'val9' ], 'key1' => [ 'val1', 'val2' ], 'key3' => [ 'val10' ] };
Regards,
Edward