Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^2: Logical operations on arrays

by Jenda (Abbot)
on Oct 04, 2012 at 23:03 UTC ( #997342=note: print w/ replies, xml ) Need Help??

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;

Enoch was right!
Enjoy the last years of Rome.

Comment on Re^2: Logical operations on arrays
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997342]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2015-11-25 15:10 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (680 votes), past polls