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

Re: Logical operations on arrays

by Kenosis (Priest)
on Oct 04, 2012 at 15:59 UTC ( #997252=note: print w/ replies, xml ) Need Help??


in reply to Logical operations on arrays

One option is to use List::Compare:

use strict; use warnings; use List::Compare; my @a = qw(a b c); my @b = qw(b c d); print "\@a = @a\n\@b = @b\n\n"; print '@a AND @b = ', arrayANDCompare( \@a, \@b ), "\n\n"; print '@a OR @b = ', arrayORCompare( \@a, \@b ); sub arrayANDCompare { my ( $a, $b ) = @_; return List::Compare->new( $a, $b )->get_intersection; } sub arrayORCompare { my ( $a, $b ) = @_; return List::Compare->new( $a, $b )->get_union; }

Output:

@a = a b c @b = b c d @a AND @b = bc @a OR @b = abcd


Comment on Re: Logical operations on arrays
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2015-07-28 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls