For every arrayref in the list, transform the arrayref's array as follows: if the value has been seen before, ignore it. Otherwise, include it. Either way, make sure you note that you've seen it. NOTE! This removes any value that's seen more than once. I think, though, that you want to remove entire pairs that are seen more than once. Your use of arrows makes it seem like you care about pairs. After all, it's like =>, used in marking hash pairs. So, if you indeed meant duplicated arrayrefs, not duplicated deep values...my %seen_values; for my $aref (@array_of_arrayrefs) { $aref = [ map { $seen_values{$_}++ ? () : $_ } @$aref ]; }
It's the same thing, but we're using a two-level hash. After all, it's a lot like what you were thinking, isn't it? If this isn't clear, I can elaborate on how it works. I know using $_ makes some people glaze over...my %seen_values; my @new_AofA = map { $seen_values{$_->[0]}{$_->[1]}++ ? () : $_ } @Aof +A;
In reply to Re: Remove Duplicates from an Array of Arrays
by rjbs
in thread Remove Duplicates from an Array of Arrays
by Dru
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |