in reply to removing duplicates from an array of hashes
Here's a grep solution:
my %seen; @$ref = grep { ! $seen{$_->{id}}++ } @$ref;
My test is in the spoiler.
Script:
#!/usr/bin/env perl use strict; use warnings; use Data::Dump; my $ref = [ map { +{ id => $_ } } qw{a b c b} ]; dd $ref; my %seen; @$ref = grep { ! $seen{$_->{id}}++ } @$ref; dd $ref;
Output:
[{ id => "a" }, { id => "b" }, { id => "c" }, { id => "b" }] [{ id => "a" }, { id => "b" }, { id => "c" }]
-- Ken
|
|---|