in reply to Eliminate exact duplicates from array of hashes
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Eliminate exact duplicates from array of hashes
by LanX (Saint) on Oct 10, 2019 at 02:28 UTC |