in reply to Re: Printing and Removing Duplicates in Arrays
in thread Printing and Removing Duplicates in Arrays
However, you don't need to check if an element exists in the current array:
my @ary1 = (1, 2, 3, 4, 5, 6, 7); my @ary2 = (6, 7, 8, 9, 10, 11); my %h1; my %h2; @h1{@ary1} = undef; @h2{@ary2} = undef; my @dupes; @ary1 = grep {not exists $h2{$_} or not push @dupes, $_} @ary1; @ary2 = grep {not exists $h1{$_} } @ary2; print "ary1 is @ary1 \n"; print "ary2 is @ary2 \n"; print "dupes were @dupes \n";
Or even just this:
@dupes = grep { exists $h2{$_}} @ary1; @ary1 = grep {not exists $h2{$_}} @ary1; @ary2 = grep {not exists $h1{$_}} @ary2;
--
John.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Printing and Removing Duplicates in Arrays
by andye (Curate) on Aug 21, 2002 at 11:14 UTC |