How can I find the union/difference/intersection of two arrays?
1. It works #
my @simpsons = ("homer","bart","marge","maggie","lisa"); my @females = ("lisa","marge","maggie","maude"); my %simpsons = map{$_ =>1} @simpsons; my %females = map{$_=>1} @females; # the intersection of @females and @simpsons: my @female_simpsons = grep( $simpsons{$_}, @females );
2. Quantum::Superpositions #
Quantum::Superpositions 모듈 사용. 느리지만, 제법 readable.
http://search.cpan.org/~lembark/Quantum-Superpositions-2.02/lib/Quantum/Superpositions.pm
http://search.cpan.org/~lembark/Quantum-Superpositions-2.02/lib/Quantum/Superpositions.pm
use Quantum::Superpositions; my @a = (1,2,3,4,5,6,7,8,9,10); # integers my @b = (2,4,6,8,10,12,14,16,18,20); # doubled my @unionAB = sort { $a <=> $b } eigenstates( any(@a, @b) ); my @intersectionAB = sort { $a <=> $b } eigenstates( any(@a) == any(@b+) ); my @differenceAB = sort { $a <=> $b } eigenstates( any(@a) != all(@b+) );