in reply to Re: is there a more simple way to have the intersection of two lists ?
in thread is there a more simple way to have the intersection of two lists ?

my %seen; $seen{$_}=1 for @list1; my @intersection = grep ++$seen{}==2, @list2;
You are missing a $_ there. And it doesn't work. (Consider @list1=(); @list2=qw(foo foo);.)

Replies are listed 'Best First'.
Re^3: is there a more simple way to have the intersection of two lists ?
by ikegami (Patriarch) on Mar 19, 2008 at 06:48 UTC

    Hum, right. I over-optimized. I should have stuck to the general solution (i.e. accepts more than two sets) I first wrote.

    my %seen; $seen{$_}|=1<<0 for @list1; $seen{$_}|=1<<1 for @list2; my @intersection = grep $seen{$_}==(1<<2)-1, keys %seen;

    It loses any order, though.