Forum Moderators: coopster & phranque

Message Too Old, No Replies

eliminating excessive duplicates

         

SlowMove

3:29 am on Feb 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm starting to understand Perl, but I'm faced with a difficult problem. I'm trying to compare some arrays of various sizes with unordered elements. What I want to do is find out if the array that I'm checking has all of it's elements included in any of the other arrays. For example, checking the first array with the second would show that all of the elements are included:

@check = ( 3, 4, 7, 2 );
@other = ( 2, 4, 5, 7, 3);

Any help would be appreciated.

xunker

6:10 am on Feb 29, 2004 (gmt 0)

10+ Year Member



So you want to see if what's stored on @check is also stored in @other, right?

It's easy, though time consuming (as in consuming CPU cycles) using the "foreach" command:


my @not_there; # where we can mark values *not* duped
foreach my $c (@check) {
my $there;
foreach my $o (@other) {
if ($o eq $c) { $there++; }
}
if (! $there) { push @not_there, $c; }
}

..then, in theory (I haven't run the above code) you should have a list of all the values NOT duplicated in @not_there.