Quoting Robin Houston ([EMAIL PROTECTED]):
> I think the moral of the story is that set operations can be done more
> efficiently on hashes than arrays.
But hashes waste masses of memory. This sort of thing is why Lisp
programmers sneer at Perl programmers. The most efficient way to do set
operations is with sorted arrays*, but Perl doesn't have primitives for
those so it's not Fun.
Adam
* Ok, ok, in some cases bitmaps are better, before anyone jumps on me
Here's some non-Fun example code:
# assumes @ary1 and @ary2 are sorted
my($a, $b, @ary3);
$a=$b=0;
while ($a<@ary1 && $b<@ary2) {
my $c = $ary1[$a] <=> $ary2[$b];
if ($c<0) {
push(@ary3, $ary1[$a]);
++$a;
} elsif ($c>0) {
++$b;
} else {
++$a;
++$b;
}
}
if ($a<@ary1) {
push(@ary3, @ary1[$a .. $#ary1]);
}
--
Adam Rice -- [EMAIL PROTECTED] -- Blackburn, Lancashire, England