http://www.perlmonks.org?node_id=997342


in reply to Re: Logical operations on arrays
in thread Logical operations on arrays

There's no reason to work hard to set the values in the hash to ones, leave them undefined and use exists() within the grep{}. Also there is no reason to push the elements into the @intersection, just assign them.

my %hash1; @hash1{@array1} = (); my @intersection = grep {exists $hash1{$_} } @array2;

Jenda
Enoch was right!
Enjoy the last years of Rome.