Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Not getting proper output value

by suvendra123
on Apr 05, 2021 at 17:02 UTC ( #11130852=perlquestion: print w/replies, xml ) 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: Not getting proper output value
by pryrt (Monsignor) on Apr 05, 2021 at 17:42 UTC

    How is this question any different than most of your other recent questions?

    The same basic ideas work for most, if not all, of those questions.

    Until you understand the solutions that have been freely given to you in those other discussions, you will never be able to solve these problems for yourself.

    As you have been told repeatedly, PerlMonks is not a codewriting or personal debug service.

    Your specific question was "where is the mistake?". The snarky answer is "It appears there are mistakes on lines 9, 10, and 18, at the very least". More information to make it less snarky: Since you are not getting the output you desire, then you do not appear to have built up a reasonable regex to perform the transformation you desire -- hence, the "mistake" is in the lines that build that regex.

    A more helpful response (but I do not claim it's an answer): Can you explain what you thought those three lines of code were doing? And why you thought they would match your input data to create your desired output data? If you cannot explain your thought process, then you need to go back and study regex and perl fundamentals again, using the resources already pointed out to you. If you are able to explain your thought process, then maybe someone here will be able to explain to you what was wrong in your mental algorithm. Because there have been dozens of replies to your previous posts, and you don't seem to be understanding the regex concepts that those solutions have shown you; if that's the case, then having someone give you yet another solution to this specific problem won't actually help you, because you won't be able to fix the problem in your next regex in a few days/weeks/months -- and that is then a waste of your time, let alone the time of those who have tried to help you. You need to put in the effort to learn... and the first step in that effort is to explain why you thought this code would work.

    Note: I've never replied to any other of your threads, because I'm not really a regex expert, and lots of other people have given you much better answers than I could. But what I hate seeing in forums like this is when people keep asking the same kind of question without every apparently growing in their understanding -- which either means that the forum regulars haven't found the root cause of why you cannot figure it out yourself, or because the person asking is too lazy to learn on their own. I always desire that any such question is not actually the second circumstance. And assuming that it's the first circumstance for you, I thought I would step in and try to phrase things differently than you've previously seen, so that maybe you would be able to provide insight into your thought processes, and thus the experienced Monks here would be able to help correct your misunderstanding that is preventing you from solving these sorts of problems.

Re: Not getting proper output value
by AnomalousMonk (Bishop) on Apr 05, 2021 at 17:38 UTC

    Your posted code has some problems:

    • It does not compile. There's a problem with the statement
         my $b = qr{  abc_p | abc) }xms;
      (already noted by LanX).
    • Your test data does not include an instance of the 'int abc;' input variation.
    • More of an annoyance than a problem: AFAICT, you have never said what version of Perl you are running under.
    • Even more annoying: You still are not posting in a Test::More format.

    A general point: Don't you see that you are trying to process two basically different patterns? 'int abc;' gets altered (apparently) unconditionally, but '.abc(abc_p)' gets altered only if the 'abc' or 'abc_p' pattern is repeated. Recognizing the patterns you're dealing with is the first step toward solving this (or any) regex problem.

    Give a man a fish:  <%-{-{-{-<

      Perl v5.24.2 , I am running
        Perl v5.24.2 ...

        Ok, thank you. This version gives you the very useful regex Extended Patterns of version 5.10 and the nice-to-have /r modifier for s/// substitution (update: of version 5.14).

        Give a man a fish:  <%-{-{-{-<

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Not getting proper output value
by LanX (Cardinal) on Apr 05, 2021 at 17:13 UTC
    Which output/errors do you get and what do you miss?


    do you notice something here?

    qr{  abc_p | abc) }xms;


    I ran the code because this looked too obvious to be true, alas ...

    Unmatched ) in regex; marked by <-- HERE in m/ abc_p | abc) <-- HERE + / at d:/tmp/pm/ line 10.

    Perl even points out the correct line ...

    ... sigh ...

    ...downvoted, again.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2021-06-22 08:00 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (102 votes). Check out past polls.