in reply to List Comparison

This is a more computation-efficient way that takes advantage of the fact that hash lookups are essentially O(1):

my %listA; @listA{@a}=(); foreach my $item ( @b ) { next if exists $listA{$item}; push @c, $item; }

Of course CPAN is your friend for this sort of thing. But I wanted to show the hash technique because it replaces a single slow O(n^2) algorithm with two faster O(n) operations, which is an order of magnitude more computationally efficient (but more of a memory hog too).


Dave

Replies are listed 'Best First'.
Re^2: List Comparison
by fergal (Chaplain) on Sep 10, 2004 at 10:20 UTC
    You can also turn that loop into another hash operation, which will probably make it even faster.
    my %listA; @listA{@a}=(); delete @listA{@b}; @c = keys %listA;