Your skill will accomplishwhat the force of many cannot PerlMonks

### Unable to find my mistake

by suvendra123 (Initiate)
 on Mar 17, 2021 at 19:36 UTC Need Help??

suvendra123 has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Unable to find my mistake
by GrandFather (Saint) on Mar 17, 2021 at 23:07 UTC
```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;
[download]```

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
A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Unable to find my mistake
by haj (Priest) on Mar 17, 2021 at 22:42 UTC

I find it impossible to find a mistake since I have no idea what output you were expecting. But anyway: Running the command through the debugger is usually quite useful in such cases:

perl -d abc.pl pqr.txt
I am getting output as
```.dgrs(dgrs_1;
.dgrs(dgrs_2;
.dgrs(dgrs_3;
.mgs(mgs_1;
.mgs(mgs_2;
.mgs(mgs_3;
[download]```
But expected output should be
```dgrs_1(dgrs_1);
.dgrs_2(dgrs_2);
.dgrs_3(dgrs_3);
.mgs_1(mgs_1);
.mgs_2(mgs_2);
.mgs_3(mgs_3);
[download]```
Re: Unable to find my mistake
by ikegami (Patriarch) on Mar 18, 2021 at 07:55 UTC

fyi, this was posted (just as badly) on StackOverflow. No mention of crossposting.

Seeking work! You can reach me at ikegami@adaelis.com

Log In?
 Username: Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11129846]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2022-06-25 14:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My most frequent journeys are powered by:

Results (83 votes). Check out past polls.

Notices?