Ananad,
This may be 'too much information', but I was literally putting this example together for a colleague yesterday and thought it was applicable:
use strict; use warnings; use Quantum::Superpositions; my @a = (1, 3, 5, 7, 9, 11); my @b = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); my @intersect = eigenstates(any(@a) == any(@b)); my @union = eigenstates(any(@a, @b)); my @diff = eigenstates(any(@b) != all(@a)); print join(', ', @intersect)."\n"; print join(', ', @union) ."\n"; print join(', ', @diff) ."\n";
Which outputs:
11, 1, 3, 7, 9, 5 6, 11, 3, 7, 9, 12, 2, 8, 1, 4, 10, 5 6, 12, 2, 8, 4, 10
I guess the 'issue' is you need the 'Quantum::Superpositions' module (thanks Damian!), from what I hear it isn't super quick on larger arrays, and the output order isn't guaranteed.
Perl6 may have operators that act very similar called junctions (any,all,none).
Regards,
Kurt
In reply to Re: Comparing arrays in perl.
by whereiskurt
in thread Comparing arrays in perl.
by anand_perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |