Unfortunately it requires an eval step...
Here a way to avoid it
use strict; use warnings; use Data::Dump qw/pp dd/; 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 %seen; my @unique = grep { not $seen{pp $_}++ } @test_data; #pp \%seen; pp \@unique;
Sadly uniq doesn't offer to provide an optional block (analog to sort ) to emulate this behavior with code like
uniq { pp $_ } @test_data
Please be aware of possible side effects when having circular data.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
In reply to Re: Eliminate exact duplicates from array of hashes
by LanX
in thread Eliminate exact duplicates from array of hashes
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |