in reply to array difference
Try this:
my @a = ( 1, 2, 3, 4, 5, 6 ); my @b = ( 3, 4, 5, 6, 7, 8 ); my %a_lookup; @a_lookup{@a} = (); my @b_only = grep { not exists $a_lookup{$_} } @b; print "@b_only\n";
If my calculations are correct, this ought to do the trick. ;)
Update: Whenever I see a question like this I think to myself, "That sounds like something Quantum::Superpositions could do with grace and ease. While it's true that the Damian's module does accomplish this task simply and easily, it took a conversation in the Chatterbox with tye and merlyn before the actual solution became apparent to me. Credit merlyn for coming up with the Quantum::Superpositions solution at first guess... for my part, I just started the conversation rolling until an expert could come along and get it right. ;)
use Quantum::Superpositions; my @a = ( 1 .. 6 ); my @b = ( 3 .. 8 ); print "$_\n" foreach eigenstates( any( @b ) != all( @a ) );
Beauty is in the eye of the beholder, but to my mind's eye that's beautiful. Unfortunately, its simplicity is critically deceptive; don't try this with lists of a thousand elements. Using quantum superpositions on large sets becomes breathtakingly inefficient.
Dave
|
|---|