in reply to Combining two hashes
Prints:#!/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;
$VAR1 = { 'key2' => [ 'val9' ], 'key1' => [ 'val1', 'val2' ], 'key3' => [ 'val10' ] };
|
|---|