Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Matching elements inside two array

by ameezys (Acolyte)
on Apr 10, 2019 at 17:07 UTC ( #1232414=note: print w/replies, xml ) Need Help??

in reply to Matching elements inside two array

Sorry I forgot to mention the algorithm is that if the data inside input_A and input_B matches input_array, then the matching data for both input A and input B will store the value of CC0 and CC1 which is 1,1.

Replies are listed 'Best First'.
Re^2: Matching elements inside two array
by AnomalousMonk (Bishop) on Apr 10, 2019 at 20:16 UTC
    ... 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:  <%-{-{-{-<

      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?

        $ ./ 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 #!/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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2020-07-12 10:31 GMT
Find Nodes?
    Voting Booth?

    No recent polls found