Since it's you, here is my suggestion:
Update: My "solution" is now shamefully hidden in readmore-tags because it doesn't give you what was asked for. My solution simply gives you (stringified) all elements whch are in the first or the second array but not in both.
use strict; use warnings; use Data::Dumper; my @a = (43,43,44); my @b = (43,43); my @c= difference(\@a, \@b); print Dumper \@c; my @p = ( 1,1,1,1,1,2,2,2,3,3,4,5,6); my @q = ( 1,2,3,4,5,6 ); my @r= difference(\@p, \@q); print Dumper \@r; sub difference { my ($a, $b)= @_; my %d; ++$d{$_} foreach @$a; --$d{$_} foreach @$b; return map { ($_) x abs $d{$_} } keys %d; }
Wouldn't it be you, I would have cried H O M E W O R K! ;-)
Update: Removed an overseen "my $d". Thanks to betterworld
In reply to Re: Difference arrays.
by Skeeve
in thread Difference arrays.
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |