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.

Replies are listed 'Best First'.
Re^2: Using hashes for set operations...
by LanX (Saint) 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.