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.


In reply to Output not correct by nursyza

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.