⭐ in reply to How do I find if an array has duplicate elements, if so discard it?
use strict ; use warnings ; use Data::Dumper ; sub has_dups { my $arr = shift ; my %counter ; foreach ( @$arr ) { return 1 if $counter{$_}++ ; } return 0 ; } my @A = (1, 2, 3, 4, 5) ; my @B = (6, 7, 7, 8, 9) ; my @C = (10, 11, 12, 13, 15) ; my @D = grep { !has_dups($_) } ( \@A, \@B, \@C ) ; print Dumper( \@D ) ;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Answer: Clarify: How do I find if an array has duplicate elements, if so discard it?
by ysth (Canon) on Nov 07, 2003 at 10:11 UTC |
In Section
Seekers of Perl Wisdom