http://qs321.pair.com?node_id=1232419


in reply to Re: Matching elements inside two array
in thread Matching elements inside two array

... if the data inside input_A and input_B matches input_array ... [emphasis added]

Unfortunately, you also forgot to mention exactly what "matches" means in the context of your OP. Can you please at least say which of the responses you have so far received come closest to what you want?


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^3: Matching elements inside two array
by ameezys (Acolyte) on Apr 11, 2019 at 02:12 UTC
    Matches meaning that the any of the data for input A and input B is listed in the input array. So the listed data is the data that I want to store value of CC0 and CC1.
      I am curious as to what these values represent in "real life". Looks like perhaps some sort of a HW gate?
      Why the differentiation between inputs A and B?

      I suppose:
      If an input_array token (like N3) is in both A and B, then: CC0=1 and CC1 =1.
      If an input_array token is in A but not in B, then "only 1 input is PI".
      If an input_array token is not in A regardless whether it is in B or not, then: "this is a wire".

      Looks odd to me...Is this logic correct? Is the case where input_array token is in B but not in A important? obviously in A but not in B is a special case.

      Is any of Athananius' source helpful? Does it capture any of the logic you seek?

      $ ./1.amee.pl N1: only 1 input is PI N2: this is a wire N6: this is a wire N7: this is a wire CC0[N3] = 1 CC1[N3] = 1 $ cat 1.amee.pl #!/usr/bin/perl use 5.016; use strict; use warnings; use List::Util qw( any ); my @input_array = qw( N1 N2 N3 N6 N7 ); my @input_A = qw( N1 N3 N11 N11 N10 N16 ); my @input_B = qw( N3 N6 N2 N7 N16 N19 ); my %primaryCC0; for my $inputKey (@input_array) { if (any { $_ eq $inputKey } @input_A) { if (any { $_ eq $inputKey } @input_B) { @{ $primaryCC0{$inputKey} } = (1, 1); } else { print "$inputKey: only 1 input is PI\n"; } } else { print "$inputKey: this is a wire\n"; } } for my $key (sort keys %primaryCC0) { my ($CC0, $CC1) = @{ $primaryCC0{$key} }; print "CC0[$key] = $CC0\n"; print "CC1[$key] = $CC1\n"; } __END__ $

      What I find confusing about this script is non-descriptive output. For example, there is nothing in this problem that has anything to do with PI.