多次元配列のネストした配列から重複した値を除く
#!/usr/bin/env perl use strict; use warnings; use 5.014; use Data::Dumper; my @duplicated_list = ( ['apple', 'banana', 'orange', 'strawberry', 'pineapple', 'grapefruit', 'grapefruit'], ['apple', 'banana', 'orange', 'strawberry', 'pineapple', 'grapefruit'], ['apple', 'banana', 'orange', 'strawberry', 'pineapple', 'mango'], ['apple', 'banana', 'orange', 'strawberry', 'pineapple', 'mango', 'coconut'], ['apple', 'banana', 'orange', 'strawberry', 'pineapple', 'coconut'], ['apple', 'banana', 'orange', 'strawberry', 'pineapple', 'papaya'], ); my @unique_lists = (); @unique_lists = map { my %parsed_list; [grep ! $parsed_list{$_}++, @$_] } @duplicated_list; print Dumper(@unique_lists);
結果。
$VAR1 = [ 'apple', 'banana', 'orange', 'strawberry', 'pineapple', 'grapefruit' ]; $VAR2 = [ 'apple', 'banana', 'orange', 'strawberry', 'pineapple', 'grapefruit' ]; $VAR3 = [ 'apple', 'banana', 'orange', 'strawberry', 'pineapple', 'mango' ]; $VAR4 = [ 'apple', 'banana', 'orange', 'strawberry', 'pineapple', 'mango', 'coconut' ]; $VAR5 = [ 'apple', 'banana', 'orange', 'strawberry', 'pineapple', 'coconut' ]; $VAR6 = [ 'apple', 'banana', 'orange', 'strawberry', 'pineapple', 'papaya' ];