Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: [Solved]Need to extract a particular block of lines between two patterns

by sundialsvc4 (Abbot)
on Nov 09, 2017 at 20:52 UTC ( #1203082=note: print w/replies, xml ) Need Help??


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

“Thank you, all, for once-again clarifying your by-now ... (have you actually bothered to notice this?) ... “who really cares anymore anyway,“ completely inbred, completely political ... positions?

I already understand that there are a double-handful of you, who, upon this web-site about which an ever-shrinking number of individuals actually cares about anyway, continue to determinedly maintain a vendetta about a specific Monk.   (So far as I can tell, “at the exclusion of each and every other such participant here.”)

But let’s look at the source code, shall we?

my $count = 0; 11 while (<$fh_r>) { 12 if (/START/ .. /END/) { 13 $count++ if /START/; 14 print if ($count == 2); 15 } 16 }

Do you see the very-obvious bug in the code?   Obviously you do.   There is only one point in time when $count will be exactly equal to 2, and anyone could spot the flaw immediately.

Therefore, I, in entirely good faith, spelled out the basics of an alternative algorithm which not only would actually work, but which would be future-maintainable.   (As a manager right now of more than a dozen people who would individually qualify as “Perl Monks,” I happen to think that my point-of-view has certain weight.   Not to mention having written computer software for now just over four decades and counting ... how old are you?)

Nevertheless, I daresay that you, in your still-determined pursuit of your still-pointless vendettas from, by now, “a full decade ago,” never once bothered to consider a single thing that I had actually said to the OP, except for the fact that sundialsvc4 had been the one to post it.   In so doing, you frankly completely-voided your assumed position of authority with regards to what the OP actually had to say – this being the entire reason that (s)he came here in the first place.

So, do you not think that it is well past the appointed time(!) to “just let bygones be bygones?”   I rather think that most of the c-u-s-t-o-m-e-r-s which this website somehow still attracts would agree with me.   To them, I daresay, you are today just making noise.

  • 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 (Abbot) 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 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 AnomalousMonk (Chancellor) 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 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1203082]
help
Chatterbox?
[Corion]: But at least headers should be available

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2017-12-13 12:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (361 votes). Check out past polls.

    Notices?