in reply to matching arrays

Make a bit vector, each bit corresponding to a search term (bit 0 means 'male', bit 1 'female'). Convert your occurences into bit vectors as well and use those as keys in your tally ([ 'male', 'child'] would have bits 0 and 2 set (0b101)). Then turn the bit vector keys back into the original terms on the way out.

Update: I was going to expand on this but connectivity on the train was kinda spotty. At any rate, see perldoc -f vec and search for Set modules on CPAN (since that's basically what you're asking about).

Replies are listed 'Best First'.
Re: Re: matching arrays
by rsiedl (Friar) on May 25, 2004 at 21:31 UTC
    bit vectors are something new to me. I'll do some research and check them out. Cheers.
      This code is a simple version of the bit vector code:

      my %bits = ('male' => 1, 'female' => 2, 'child' => 4); my %tally; foreach my $array_ref ( @occurances ) { my $vector = 0; $vector += $bits{$_} for @$array_ref; $tally{$vector}++; }
      So, if each occurrence can have each of 'male', 'female', etc. only once, the vector for each permutation is unique. Then get the vector for each possible occurrence, and see how many times each appeared in the %tally hash.

      (++ to all the replies in this thread, because at this stage in the morning, I couldn't work out what the OP wanted at all ;) )