Merging two hashrefs in Perl

I came across an interesting and very simple way to merge the contents of two hashrefs today. A hash is made up of pairs – a key and a corresponding value. As an example, the following can be pasted into a shell session on most machines that have perl installed.
perl -MData::Dumper -le ‘
$x = { a => 1, b => 2 };
$y = { c => 3, d => 4 };
$x = { %$x, %$y };
print Dumper($x);

Continue reading