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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found