Site menu:

Back to examples

Perl Example - Merge Two Hashes

#################################################
#Version 0.1                                    #
#Free to use for any purpose                    #
#No credits or backlink required                #
#Author : Shaji Kalidasan (shajiindia@yahoo.com)#
#################################################
use strict;
use warnings;
use Hash::Merge qw/merge/;
use Data::Dumper;

my %team1 = (
    player => {
        name           => 'Tendulkar',
        genre          => 'Batsman',
    }
);

my %team2 = (
    player => {
        age            => '39',
        country        => 'India',
        nickname       => 'God of Cricket',
        test_hundreds  => '51',
        odi_hundreds   => '49'
    }
);

my %merged = %{ merge( \%team1, \%team2 ) };

print Dumper \%merged;