http://www.perlmonks.org?node_id=1203082


in reply to [Solved]Need to extract a particular block of lines between two patterns

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re: [Solved]Need to extract a particular block of lines between two patterns
  • Download Code

Replies are listed 'Best First'.
Re^2: [Solved]Need to extract a particular block of lines between two patterns
by haukex (Archbishop) on Nov 09, 2017 at 22:21 UTC
    Do you see the very-obvious bug in the code? Obviously you do.

    Sorry, but I don't. Could you explain or demonstrate the bug with an SSCCE?

    There is only one point in time when $count will be exactly equal to 2, and anyone could spot the flaw immediately.

    That seems to be the OP's specification, "extract only the second block of lines that meet the pattern" (emphasis mine). Note how the OP's sample input data explicitly says "lines not to be extracted". I've added an extra block to the input for testing:

    use warnings; use strict; my $count = 0; while (<DATA>) { if (/START/ .. /END/) { $count++ if /START/; print if ($count == 2); } } __DATA__ abc efg ... START lines NOT to be extracted 1 END START lines to be extracted END START lines NOT to be extracted 2 END START lines NOT to be extracted 3 END

    Outputs:

    START lines to be extracted END

    ... which seems to me to meet the specification. Cristoforo's code also works as posted, except that it does not output the START and END markers.

    Whereas your code, once I fix all the syntax errors and change "do something with the line" to a print, outputs for the same sample input:

    lines to be extracted lines NOT to be extracted 3

    Update: Added the last two paragraphs, and minor edits for clarity.

Re^2: [Solved]Need to extract a particular block of lines between two patterns
by Laurent_R (Canon) on Nov 09, 2017 at 23:44 UTC
    To start with, I'm very sorry, but I really don't have any vendetta against you (nor against any other monk here for that matter). Maybe some people around here do, I don't know for sure, but not me.

    My post was very factual: besides being syntactically wrong, the code you posted (once fixed) wasn't going to do what the OP was asking for. That's it. Nothing to add. Period.

    I would have stopped here if it weren't for your response.

    But your answer calls for additional comments.

    Don't make yourself yourself a victim of others. Here, my personal opinion was that your code was wrong, and I explained in which respects I thought your code suggestion was wrong. Leaving aside the syntax mistakes, you code (if fixed syntactically) doesn't do what what the OP asked for. I only reported that fact. Maybe, after all, I was wrong and your code was right (I really don't think so), but your answer just complains about people not being nice with you, but does not actually discuss in any way my objections to your code.

    Now, I would add that, since in your initial post you insisted quite a bit on thorough testing, perhaps you could check at the very least whether your code could compile flawlessly (I am willing to suppose and accept that: perhaps, you misunderstood the OP's original intent). If you can't do it, at least, ask one of your boys to do it for you.

    I am sure that I have made once in a while silly mistakes in code samples I have posted here or on some other forums; in that case, I would say: "Sorry, I made a mistake," or, maybe, "Sorry, not enough coffee this morning," or some other sentence trying to apologize, or whatever. But, at least, I would recognize my mistake and not accuse people of doing that to me because they don't like me.

    In the case in point, even the Perl compiler appears not to like you--or rather what you write. Yeah, maybe you've got a good reason to become paranoid. Even machines are against you. Or, perhaps, you should question yourself.

    Finally, I have serious doubts about whether you actually know Perl. Your syntax mistakes are glaring. "//" instead of "#" for comments, "false" and "true" for Boolean values, that's pretty damning. Yes, you should learn that "false" has a true value.

    Oh, and BTW, I agree with haukex and don't see "the very-obvious bug" in the OP's code (but I do see several in yours), but that's secondary to what I want to say here.

    Yes, there are probably monks around here who don't like you, or, rather, don't like what you write. But ask yourself: maybe they have some good reasons for that.

Re^2: [Solved]Need to extract a particular block of lines between two patterns
by AnomalousMonk (Archbishop) on Nov 11, 2017 at 15:58 UTC
    As a manager right now of more than a dozen people who would individually qualify as “Perl Monks,” ...

    Yeah, I've had nightmares | managers like that.


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

Re^2: [Solved]Need to extract a particular block of lines between two patterns
by Anonymous Monk on Nov 10, 2017 at 00:06 UTC
    obvious troll is obvious
Re^2: [Solved]Need to extract a particular block of lines between two patterns
by Anonymous Monk on Nov 10, 2017 at 12:11 UTC
    Are you drunk? High? Have mental health issues? You don't know perl basics, stop telling people on a perl forum that you do. You fall into several of these categories: https://en.wikipedia.org/wiki/Victim_playing
    If you want to help people, stop posting trash like this. Stop posting when you don't know anything at all about the topic under discussion (computers, perl, sanity)
Re^2: [Solved]Need to extract a particular block of lines between two patterns
by Anonymous Monk on Nov 11, 2017 at 10:51 UTC

    have you actually bothered to notice this

    you reply to wrong node again didnt you notice?

    Flush it
Re^2: [Solved]Need to extract a particular block of lines between two patterns
by Anonymous Monk on Nov 11, 2017 at 01:07 UTC

    All your responses come after the thread was marked "Solved"

    Go away Mike Robinson you spammer