in reply to compare 2 arrays for intersect diff and commmon values
It looks to me that this is not doing what you think:
as those arrays are in fact arrays of arrays. Try getting rid of that and putting my %count at the top of your sub and counting within the other loops:my %count = (); foreach my $device (@current_list, @temp_devicelist) { $count{$device}++; }
Then you can print out the values:my %count; # ... for ($n=0; $n < $size; $n++) { our $device=$current_list[$n][0]; $count{$device}++; } # ... for ($n=0; $n < $size; $n++) { our $tempdevicelinks=$temp_list[$n][0]; $count{$tempdevicelinks}++; } # ... my @difference = grep { $count{$_} == 1 } keys %count; my @intersect = grep { $count{$_} == 2 } keys %count; my @union = keys %count;
print "Difference:\n"; print "$_\n" for @difference; print "Intersect:\n"; print "$_\n" for @intersect; print "Union:\n"; print "$_\n" for @union;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: compare 2 arrays for intersect diff and commmon values
by rasgolla (Initiate) on Mar 25, 2014 at 05:53 UTC | |
by tangent (Parson) on Mar 25, 2014 at 06:14 UTC | |
by rasgolla (Initiate) on Mar 25, 2014 at 08:23 UTC | |
by tangent (Parson) on Mar 25, 2014 at 16:18 UTC | |
by rasgolla (Initiate) on Mar 26, 2014 at 02:54 UTC |
In Section
Seekers of Perl Wisdom