This was the first thing that popped into my head:
Code:
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 ) ] );
'
Output:
$ref = \[
{
'id' => 'a'
},
{
'id' => 'b'
},
{
'id' => 'c'
},
{
'id' => 'b'
}
];
$temp = \[
{
'id' => 'a'
},
{
'id' => 'b'
},
{
'id' => 'c'
}
];
Hope that helps.