in reply to Finding an intersection of two sets, lean and mean
sub intersection { my ( $list1, $list2 ) = @_; my %hash; @hash{@$list1} = undef; my @intersection = grep { exists $hash{$_} } @$list2; return @intersection }
Update: Fixed mistake in my code (map -> grep) Compare mine to yours and I think you'll notice a difference.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Finding an intersection of two sets, lean and mean
by Sinister (Friar) on Jun 29, 2005 at 14:31 UTC | |
by Sinister (Friar) on Jun 29, 2005 at 14:52 UTC | |
by dragonchild (Archbishop) on Jun 29, 2005 at 15:00 UTC | |
by dragonchild (Archbishop) on Jun 29, 2005 at 14:36 UTC | |
by Sinister (Friar) on Jun 29, 2005 at 14:42 UTC | |
by dragonchild (Archbishop) on Jun 29, 2005 at 14:57 UTC |