Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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;

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997342]
help
Chatterbox?
[marto]: Corion, I'll talk to you later, but that are is generally fine :)
[hippo]: Just not sure that the expense and hassle is worth the benefit.
[LanX]: expense? .... meeting ppl is inspiring ...
[LanX]: ... and it might be your last chance ... I heard Perl is dead! OO

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (11)
As of 2018-06-20 09:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (116 votes). Check out past polls.

    Notices?