Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

How to check for the connectivity using hash

by prk (Initiate)
on Oct 01, 2019 at 11:40 UTC ( [id://11106899]=perlquestion: print w/replies, xml ) Need Help??

prk has asked for the wisdom of the Perl Monks concerning the following question:

input abc10; output v; checkinst_0( .port1(wireY), .port2(wireZ), .port3(wireX), .port4(port711), .port10 ); checkinst_2( .port5(wireYx), .port6(wireZ), .port7(wireaX), .port8(abc10), .port11 ); checkinst_3( .port5(wireYd), .port6(wireZS), .port7(wireXW), .port8(port10), .port12 );

for the above example i want to create the hash and say ".port " as source and "(wire)" as destination with the key as "checkinst_" if the destinations (wires) are same then i should print like portx of checkinstx is connected to porty of check inst y, if there is destination(wire) along the port, then eg: .port4 then i should make it as .port4(port4) and check if its connected to any port and print as earlier, if the wire (destination) is same as the one declared as input or output in the code then i should print as portx of checkinstx is connected to top if none of the above conditions are satisfied then i have to print as portx of checkinstx is left unconnected

Replies are listed 'Best First'.
Re: How to check for the connectivity using hash
by Fletch (Bishop) on Oct 01, 2019 at 12:20 UTC

    Create a parser. Parse your input into whatever representation of the connectivity you need. Walk the representation. Profit.

    Update: As before, the Graph module might be of use.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: How to check for the connectivity using hash
by tybalt89 (Monsignor) on Oct 01, 2019 at 16:45 UTC

    Please show the exact desired hash for the data in your post.

      input

      input abc10; output wireax; checkinst_0( .port1(wireY), .port2(wireZ), .port3(wireX), .port4(port711), .port10 ); checkinst_2( .port5(wireYx), .port6(wireZ), .port7(wireaX), .port8(abc10), .port11 ); checkinst_3( .port100(wireYd), .port101(wireZS), .port102(wireXW), .port103(port10), .port12 );
      $VAR1 = { 'checkinst_0' => { 'dest' => [ 'wireY', 'wireZ', 'wireX', 'port711', ], 'source' => [ 'port1', 'port2', 'port3', 'port4', ] }, 'checkinst_1' => { 'dest' => [ 'wireYx', 'wireZ', 'wireaX', 'abc10', ], 'source' => [ 'port5', 'port6', 'port7', 'port8', ] }, 'checkinst_2' => { 'dest' => [ 'wireYd', 'wireZS', 'wireXW', 'port10', ], 'source' => [ 'port100', 'port101', 'port102', 'port103', ] }, 'Implicit' => { 'source' => [ port10, port11, port12 ' ], 'dest' => [ port10, port11, port12 ' ] }, 'top' => { 'source' => [ ' abc10', ' woreax' ], 'dest' => [ ' abc10', ' woreax' ] } };
        That will be 200 US dollars, payable to the Perl Foundation.
        use 5.020; use Regexp::Grammars; my $input = <<'...'; input abc10; output wireax; checkinst_0( .port1(wireY), .port2(wireZ), .port3(wireX), .port4(port711), .port10 ); checkinst_2( .port5(wireYx), .port6(wireZ), .port7(wireaX), .port8(abc10), .port11 ); checkinst_3( .port100(wireYd), .port101(wireZS), .port102(wireXW), .port103(port10), .port12 ); ... my $parser = qr{ <start> <rule: start> <input> <output> <[checkinst]>+ <rule: input> input <identifier> ; <rule: output> output <identifier> ; <rule: checkinst> <checkinstid> [(] <ports> [)]; <rule: ports> <[port]>+ % , <rule: port> <portid> <parens>? <rule: parens> [(] <identifier> [)] <token: identifier> \w+\d* <token: checkinstid> checkinst_ \d+ <token: portid> [.]port \d+ }msx; if ($input =~ $parser) { my %r; { my $i = $/{start}{input}{identifier}; my $o = $/{start}{output}{identifier}; $r{top} = { source => [$i, $o], dest => [$i, $o], }; } { my @implicit; for my $checkinst ($/{start}{checkinst}->@*) { for my $port ($checkinst->{ports}{port}->@*) { if ($port->{parens}) { push $r{$checkinst->{checkinstid}}{dest}->@*, $port->{parens}{identifier}; push $r{$checkinst->{checkinstid}}{source}->@*, $port->{portid} =~ s/^\.//r; } else { push @implicit, $port->{portid} =~ s/^\.//r; } } } $r{Implicit} = { source => \@implicit, dest => \@implicit, }; } } __END__ %r = ( checkinst_0 => { dest => [qw(wireY wireZ wireX port711)], source => [qw(port1 port2 port3 port4)], }, checkinst_2 => { dest => [qw(wireYx wireZ wireaX abc10)], source => [qw(port5 port6 port7 port8)], }, checkinst_3 => { dest => [qw(wireYd wireZS wireXW port10)], source => [qw(port100 port101 port102 port103)], }, Implicit => { dest => [qw(port10 port11 port12)], source => [qw(port10 port11 port12)], }, top => { dest => [qw(abc10 wireax)], source => [qw(abc10 wireax)] }, )
Re: How to check for the connectivity using hash
by karlgoethebier (Abbot) on Oct 01, 2019 at 12:34 UTC

    See also. Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11106899]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 19:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found