If your input will have at most 1 set of curlies per line, this works:
use warnings;
use strict;
while (<DATA>) {
chomp;
my $concat;
if (s/({.+})/{}/) { # replace curlies' contents with just curlies
+for now
$concat = $1;
}
my @words = split /[(,]/;
$words[2] = $concat if $concat;
print "writing.reg($words[1]).write($words[3],$words[2]);\n";
}
__DATA__
write_x("top.inst1.inst2.reg",32'h30,status,"string");
write_x("mod.ins5.ins7.val",{24'h0,4'h2,variable1,variable2},status,"s
+tring");
It looks like you are parsing Verilog. If so, take a look at Verilog-Perl because (you are about to find out that) parsing Verilog is not trivial.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.