This was the first thing that popped into my head:
Code:
Output:perl -MData::Dumper -le ' my $ref = []; $ref->[0] = { id => "a" }; $ref->[1] = { id => "b" }; $ref->[2] = { id => "c" }; $ref->[3] = { id => "b" }; print Data::Dumper->Dump( [ \$ref, ], [ qw( *ref ) ] ); my $temp; my %seen; while ( my $t = shift @{$ref} ) { if (not defined $seen{$t->{id}}) { push @{$temp}, $t; $seen{$t->{id}}++; } } print Data::Dumper->Dump( [ \$temp, ], [ qw( *temp ) ] ); '
$ref = \[ { 'id' => 'a' }, { 'id' => 'b' }, { 'id' => 'c' }, { 'id' => 'b' } ]; $temp = \[ { 'id' => 'a' }, { 'id' => 'b' }, { 'id' => 'c' } ];
Hope that helps.
In reply to Re: removing duplicates from an array of hashes
by atcroft
in thread removing duplicates from an array of hashes
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |