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.
In reply to Re^2: Logical operations on arrays
by Jenda
in thread Logical operations on arrays
by ronmrdechai
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |