Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Using hashes for set operations...

by ikegami (Pope)
on May 21, 2011 at 17:00 UTC ( #906073=note: print w/ replies, xml ) Need Help??


in reply to Using hashes for set operations...

my %set1 = map { $_ => 1 } @array1; my %set2 = map { $_ => 1 } @array2; my %intersection = grep $set1{$_}, keys %set2;

That assumes true values. You're using weird values, so you might have to use exists.


Comment on Re: Using hashes for set operations...
Select or Download Code
Re^2: Using hashes for set operations...
by LanX (Canon) on May 21, 2011 at 18:50 UTC
    well this my %intersection = grep $set1{$_}, keys %set2; is wrong, you're assigning a list of keys to a hash.

    and you missed so many points from my post that I assume that you only read the headings... or how do you want to intersect sets of objects like this?

    Cheers Rolf

      and [he] missed so many points from my post that I assume that you only read the headings
      I've noticed a trend for quantity at the expense of quality, in general.
        Answering the replies to my posts has been taking a lot out of me, and taking a lot of time away from my other answers.

      Sorry, missing map { $_ => 1 }

      my %set1 = map { $_ => 1 } @array1; my %set2 = map { $_ => 1 } @array2; my %intersection = map { $_ => 1 } grep $set1{$_}, keys %set2;

      and you missed so many points from my post that I assume that you only read the headings..

      Are you trying to imply that I should have told you you need to use a hash to get the original from the stringification even you already know that?

      Or are you referring to request to avoid loops? Yeah, I missed that bit of nonsense. It's impossible to find the intersection of two sets without looping over the two sets.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2014-07-14 05:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (255 votes), past polls