use strict;
use warnings;
my $par_value = 3;
my $inData = <<INDATA;
wire [130 : 0] dgrs_1;
wire [130 : 0] dgrs_2;
wire [130 : 0] mgs_1;
wire [130 : 0] mgs_2;
wire [130 : 0] pqr_1;
wire [130 : 0] pqr_2;
int abc;
int pqr_1;
int pqr_2;
.dgrs_1(dgrs_1);
.dgrs_2(dgrs_2);
.mgs_1(mgs_1);
.mgs_2(mgs_2);
INDATA
open my $in_fh1, '<', \$inData;
while (my $line = <$in_fh1>) {
if ($line =~ m{ \A (.*dgrs) }xms) {
print "${1}_$_;\n" for 1 .. $par_value;
}
if ($line =~ m{ \A ("\.dgrs") }xms) {
print "${1}_$_;\n" for 1 .. $par_value;
}
if ($line =~ m{ \A (.*mgs) }xms) {
print "${1}_$_;\n" for 1 .. $par_value;
}
if ($line =~ m{ \A (.*pqr) }xms) {
print "${1}_$_;\n" for 1 .. $par_value;
} elsif ($line !~ m/(?:dgrs|mgs|pqr)/) {
print $line;
}
}
close $in_fh1;
seems sufficient to reproduce your problem. Check your regular expressions are matching what you expect them to.
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
-
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.
|