I'm trying to merge two hashes that hold lists inside them. The thing is that those lists are exactly the same, but because they are lists, the merger duplicates their values inside.
Any ideas how can I remove the duplication?
#!usr/bin/perl
use strict;
use warnings;
use Hash::Merge;
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
my $hash1 = {
'Instance' => [ 1,2 ]
};
my $hash2 = {
'Instance' => [ 1,2 ]
};
my $merger = Hash::Merge->new('LEFT_PRECEDENT');
my $hash3 = $merger->merge($hash2, $hash1);
print Dumper($hash3);
The output:
$VAR1 = {
'Instance' => [
1,
2,
1,
2
]
};
What I want is:
$VAR1 = {
'Instance' => [
1,
2
]
};
AFTER EDIT: I posted a continuing question.