in reply to Re: Is one array a subset of the other
in thread Is one array a subset of the other
Why all the hashes? Array lookups are faster, no? Plus this way you have no extra arrays hanging around. First argument to issubset() is a ref to the big set, second argument is a ref the alleged subset:
#!/usr/bin/perl use strict; my @a1=qw(a b c d e f g); my @a2=qw(b g); my @a3=qw(c d e f g h); sub issubset { ($a,$b)=@_; for my $x (@$b) { return ("not a subset") unless grep {$x eq $_} @$a; } return ("a subset"); } print "a2 is ",issubset(\@a1,\@a2)," of a1\n"; print "a3 is ",issubset(\@a1,\@a3)," of a1\n"; __END__ Output is: a2 is a subset of a1 a3 is not a subset of a1
HTH
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Is one array a subset of the other
by halley (Prior) on May 19, 2003 at 20:15 UTC |