⭐ in reply to How do I find unique Array in Array of Arrays?
In order to detect duplicates, one needs a way of testing equality. For non-scalar data structures, this can be tricky, or at least application dependent.
As a generic solution, one can simply stringify each datastructure and compare using string equality (eq). This technique probably breaks badly when any of the contents are objects or functions or other exotic beasts. For strings and numbers, it works pretty well.
Here, I use Data::Dumper for stringification:
my @a = ( ['a','b','c'], ['a','b','c'], ['a','b','d'], ['a','b','d'], ); my @b = do { use Data::Dumper; my %seen; map { $_->[0] } grep { !$seen{$_->[1]}++ } map { [ $_, Dumper($_) ] } @a };
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Answer: How do I find unique Array in Array of Array?
by TedPride (Priest) on May 12, 2006 at 06:33 UTC | |
by jdporter (Paladin) on May 12, 2006 at 19:32 UTC |
In Section
Seekers of Perl Wisdom