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
In reply to Re^2: Eliminate exact duplicates from array of hashes
by LanX
in thread Eliminate exact duplicates from array of hashes
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |