Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
How do i compare those two arrays whether the value on position 0 in @a is equal with the value on position 0 in @b ? i tried with this but it does not work with :@a=(0,1,0,1,0,0,0,1); @b=(0,0,1,1,0,0,0,0);
because it is checking whether values of elements are equal.@intersection = @difference = (); %count = (); foreach $element (@a, @b) { $count{$element}++ } foreach $element (keys %count) { push @{ $count{$element} > 1 ? \@intersection : \@difference }, $ele +ment; } foreach (@difference) { print $_."--"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Compare two arrays
by davido (Cardinal) on Feb 01, 2012 at 08:32 UTC | |
|
Re: Compare two arrays
by Anonymous Monk on Feb 01, 2012 at 08:33 UTC | |
|
Re: Compare two arrays
by Anonymous Monk on Feb 01, 2012 at 08:27 UTC | |
|
Re: Compare two arrays
by rustic (Monk) on Feb 01, 2012 at 13:22 UTC | |
by perl555 (Initiate) on Apr 10, 2012 at 08:05 UTC |