A few tips:
  1. Your regex is not the best. .* is "dangerous" and fraught with unintended consequences. You can go far with just \w and \s.
  2. Forget this $1,$2 stuff. Assign directly as shown below
  3. The if() is true if the regex matches, else it is false. as shown below
  4. I have many question, but this will help you get started...
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @gate_data; while (my $line = <DATA>) { if (my($gate_type,$gate_name,$ouput_gate,$input_A, $input_B) = $line =~ /^(\w+)\s+(\w+)\s+\((\w+),(\w+),(\w+)\)/) { print "$gate_type, $gate_name,$ ouput_gate, $input_A, $input_B\n +"; push @gate_data,[$gate_type, $gate_name,$ ouput_gate, $input_A, +$input_B]; } } print "@$_\n" for @gate_data; =prints nand, nand2_1,N10, N1, N3 nand, nand2_2,N11, N3, N6 nand, nand2_3,N16, N11, N2 nand, nand2_4,N19, N11, N7 nand, nand2_5,N22, N10, N16 nand, nand2_6,N23, N16, N19 nand nand2_1 N10 N1 N3 nand nand2_2 N11 N3 N6 nand nand2_3 N16 N11 N2 nand nand2_4 N19 N11 N7 nand nand2_5 N22 N10 N16 nand nand2_6 N23 N16 N19 =cut __DATA__ module circuit_17 (N1,N2,N3,N6,N7,N22,N23); 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,N11,N2); nand nand2_4 (N19,N11,N7); nand nand2_5 (N22,N10,N16); nand nand2_6 (N23,N16,N19); endmodule
Update: It appears that this output is coming from sort of wiring program. What you show here is the human readable output. There will another form of output designed as input for whatever machine is going to further fiddle with this data. I suggest you forget about parsing this data format and get whatever that other data output is. It will already be structured into records designed to handle all of the various gate types and other parts like flip-flops, registers, etc. Reverse engineering that data structure seems pointless to me.

In reply to Re: Store data into array by looping? by Marshall
in thread Store data into array by looping? by ameezys

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.