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;

    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 (Curate) 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;
      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);
Re: Unable to find my mistake
by ikegami (Pope) 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