hi, firstly this is the text file that my program is currently reading
INPUT N1, N2, N3, N6, N7;
OUTPUT N22, N23;
WIRE N10, N11, N16, N19;
NAND NAND2_1 (N10, N1, N3);
NAND NAND2_2 (N11, N3, N6);
NAND NAND2_3 (N16, N2, N11);
NAND NAND2_4 (N19, N11, N7);
NAND NAND2_5 (N22, N10, N16);
NAND NAND2_6 (N23, N16, N19);
ENDMODULE
below is the code
#!/usr/bin/perl
use warnings;
use strict;
my $filename = 'c:\Users\aqids\Desktop\SCOAP\module.txt';
my $INPUT_DATA;
my @test_input_array;
open(FH, '<', $filename) or die "Cannot open file!";
while(<FH>)
{
#READ MODULE NAME
my $MODULE_NAME = $_;
my @test_input_array;
if (defined($MODULE_NAME) && ($MODULE_NAME =~ /(MODULE \w+) /))
{
my $module_name = $1;
print "Module name = $module_name\n";
}
#READ input N1,N2,N3,N6,N7;
my $INPUT_DATA = $_;
if (defined($INPUT_DATA) && ($INPUT_DATA =~ /INPUT (.*);/))
{
my @input_array = split /,/, $1;
@test_input_array = @input_array;
my $size_input = @input_array;
print "Primary input = ";
print scalar "@input_array\n";
print "Number of primary input = $size_input\n";
}
#READ output N22, N23;
my $OUTPUT_DATA = $_;
if (defined($OUTPUT_DATA) && ($OUTPUT_DATA =~ /OUTPUT (.*);/))
{
my @output_array = split /,/, $1;
my $size_output = @output_array;
print "Primary output = ";
print scalar "@output_array\n";
print "Number of primary output = $size_output\n";
}
#READ wire N10, N11, N16, N19;
my $WIRE_DATA = $_;
if (defined($WIRE_DATA) && ($WIRE_DATA =~ /WIRE (.*);/))
{
my @wire_array = split /,/, $1;
my $size_wire = @wire_array;
print "Wires = ";
print scalar "@wire_array\n";
print "Number of wires = $size_wire\n\n";
}
my $gate_DATA = $_;
if (defined($gate_DATA) && ($gate_DATA =~ /(.*) (.*) \((.*),(.*),(
+.*)\);/) && ($gate_DATA !~ /MODULE/) )
{
my $gate_type = $1;
my $gate_name = $2;
my $gate_output = $3;
my $input_A = $4;
my $input_B = $5;
print "Gate type = $gate_type\n";
print "Gate name = $gate_name\n";
print "Output = $gate_output\n";
print "Input A = $input_A\n";
print "Input B = $input_B\n";
if (grep { $input_A eq $_ } @test_input_array)
{
print "Yes\n";
print "@test_input_array\n\n";
} else
{
print "No\n\n";
}
}
the problem right now is at....if (grep { $input_A eq $_ } @test_input_array)....as the reading for NAND2_1 should print out the first statement which is "Yes". However, it prints out No when it should be Yes. I am currently comparing the $input_A with INPUT N1, N2, N3, N6, N7. Meaning if $input_A contains any of the INPUT mention, it should print the first statement. Can someone help me fix it? Thanks.