in reply to Re: Eliminate exact duplicates from array of hashes
in thread Eliminate exact duplicates from array of hashes

Here a version with Data::Dumper which is core. (though Data::Dump is always my first installation)

use strict; use warnings; use Data::Dumper; use Test::More; sub uniq_nds{ # uniqe nested data-structures my %seen; local $Data::Dumper::Sortkeys = 1; local $Data::Dumper::Terse = 1; grep { not $seen{Dumper $_}++ } @_; } my @test_data = ( { Tag1 => 1, Tag2 => "a" }, { Tag1 => 1, Tag2 => "a" }, { Tag1 => 1, Tag2 => "b" }, { Tag1 => 1, Tag2 => "c" }, { Tag1 => 1, Tag2 => "a" }, { Tag1 => 2, Tag2 => "a" }, { Tag1 => 2, Tag2 => "d" }, { Tag1 => 2, Tag2 => "a" }, { Tag1 => 3 }, { Tag1 => "sun", Tag2 => "a" }, { Tag1 => "sun", Tag2 => "a" }, ); my $got = [ uniq_nds @test_data ]; my $expected = [ { Tag1 => 1, Tag2 => "a" }, { Tag1 => 1, Tag2 => "b" }, { Tag1 => 1, Tag2 => "c" }, { Tag1 => 2, Tag2 => "a" }, { Tag1 => 2, Tag2 => "d" }, { Tag1 => 3 }, { Tag1 => "sun", Tag2 => "a" }, ]; is_deeply( $got, $expected, 'uniq AoH' ) or diag Dumper $got; done_testing;

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice