in reply to Remove Array Duplicates from Array of Arrays
Here’s one approach: convert each inner array into a single string, and store it in a hash for future lookup:
use strict; use warnings; use Data::Dump; my @MyArrayOfArray = ( [ "hello", "day", "sun and fun" ], [ 2, "okay", "may" ], [ "hello", "day", "sun and fun" ], [ 2, "okay", "may" ], [ "hello", "sun and fun", "day" ], [ 2, "okay", "may" ], ); my (%hash, @AoA2); for (@MyArrayOfArray) { my $key = join '', @$_; push @AoA2, $_ unless exists $hash{ $key }; ++$hash{ $key }; } dd \@AoA2;
Output:
18:32 >perl 1924_SoPW.pl [ ["hello", "day", "sun and fun"], [2, "okay", "may"], ["hello", "sun and fun", "day"], ] 18:32 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Remove Array Duplicates from Array of Arrays
by AnomalousMonk (Archbishop) on Sep 01, 2018 at 09:13 UTC |