Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: compare 2 arrays for intersect diff and commmon values

by tangent (Vicar)
on Mar 25, 2014 at 06:14 UTC ( #1079646=note: print w/replies, xml ) Need Help??


in reply to Re^2: compare 2 arrays for intersect diff and commmon values
in thread compare 2 arrays for intersect diff and commmon values

Where you have our $device=$current_list[$n][0] the device name is now in $device, so that is what you want to count. Right after that add the line $count{$device}++;. Then do the same for where you have our $tempdevicelinks=$temp_list[$n][0] - add the line $count{$tempdevicelinks}++;. You could just copy and paste my sections of code into the relevant parts of your own code, and delete from your own code this bit:
foreach my $device (@current_list, @temp_devicelist) { $count{$device}++; }

Replies are listed 'Best First'.
Re^4: compare 2 arrays for intersect diff and commmon values
by rasgolla (Initiate) on Mar 25, 2014 at 08:23 UTC

    Tangent Unfortuenetly there is no output. Also now I am unable to get device name now. I am pasting changed code again.I have tried putting debug statement as well but no output.Please let me know if it is correct. I a really thankful to you that you are giiving your preciosu time to me.

    sub updatedevice() { my $n = {}; my %count; my $Device_LINK = $server->object("ICF_PersistentDataSet",$devicelinks +); my $Temp_Device_LINK = $server->object("ICF_PersistentDataSet",$tempde +vicelinks); my @current_devicelist = @{ $Device_LINK->invoke("get") }; my @temp_devicelist = @{ $Temp_Device_LINK->invoke("get") }; my %temp_list; my %current_list; my $size = @current_list; for ($n=0; $n < $size; $n++) { our $device=$current_list[$n][0]; $count{$device}++; } DEBUG( "DEBUG: - devicelinks values $device " ); my $size = @temp_list; for ($n=0; $n < $size; $n++) { our $tempdevicelinks=$temp_list[$n][0]; $count{$tempdevicelinks}++; } DEBUG( "DEBUG: - temp plc links values $tempdevicelinks " ); my @difference = grep { $count{$_} == 1 } keys %count; my @intersect = grep { $count{$_} == 2 } keys %count; my @union = keys %count; #DEBUG( "DEBUG Difference:\n"); #DEBUG( "DEBUG: - $_\n for @difference" ); #DEBUG( "DEBUG: - Intersect:\n "); #DEBUG( "DEBUG: - $_\n for @intersect "); #DEBUG( "DEBUG: - Union:\n "); #DEBUG( "DEBUG: - $_\n for @union " ); print "Difference:\n"; print "$_\n" for @difference; print "Intersect:\n"; print "$_\n" for @intersect; print "Union:\n"; print "$_\n" for @union;
      Where does @current_list and @temp_list come from? They seem to be global variables declared elsewhere in your script. To see what they actually contain use Data::Dumper to print them out, and do the same for @current_devicelist and @temp_devicelist. Insert this code and come back with the results - and don't forget to use code tags:
      use Data::Dumper; test_updatedevice(); sub test_updatedevice { print Dumper(\@current_list); print Dumper(\@temp_list); my $Device_LINK = $server->object("ICF_PersistentDataSet",$devicelinks); my $Temp_Device_LINK = $server->object("ICF_PersistentDataSet",$tempdevicelinks); my $current_devicelist = $Device_LINK->invoke("get"); my $temp_devicelist = $Temp_Device_LINK->invoke("get"); print Dumper($current_devicelist); print Dumper($temp_devicelist); }
Re^4: compare 2 arrays for intersect diff and commmon values
by rasgolla (Initiate) on Mar 26, 2014 at 02:54 UTC

    You are genious !!!! Thank you sooo Muchh Tanget ...My issue resolved... Thanks for yout time...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1079646]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2022-08-15 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?