Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: most efficient way to implement "A without B"

by tlm (Prior)
on Apr 09, 2005 at 20:25 UTC ( #446296=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use strict;
    use warnings;
    ...
    
    my $diff = relative_complement( list_2_hashref( @A ),
                                    list_2_hashref( @B ) );
    
  2. or download this
    sub intersection {
      my %tally;
      $tally{ $_ }++ for map keys %$_, @_;
      return list_2_hashref( grep $tally{ $_ } == @_, keys %tally );
    }
    
  3. or download this
    sub sym_diff {
      my %tally;
      $tally{ $_ }++ for map keys %$_, @_[0, 1];
      return list_2_hashref( grep $tally{ $_ } == 1, keys %tally );
    }
    
  4. or download this
    my $A = list_2_hashref( qw( a b c ) );
    my $B = list_2_hashref( qw( b c d ) );
    ...
    symmetric difference A, B:
    'a' => 1
    'd' => 1
    
  5. or download this
    use strict;
    use warnings;
    ...
    relative complement A, B: (a)
    intersection A, B, C: (c)
    symmetric difference A, B: (a d)
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2020-06-05 01:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (35 votes). Check out past polls.

    Notices?