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;
In Section
Seekers of Perl Wisdom