Please use <code> and </code> tags for your input data samples and expected output result (as well as code examples), and more broadly, take a look at Markup in the Monastery for formatting your posts.

It would be nice if you could show what code you have attempted and tell us in which way it fails to meet your requirement, so that we could help overcoming specific difficulties, rather than expecting us monks writing the full code for you, which would be of very little pedagogical benefit for you.

Here, the basic idea should be to read the file line by line, to set up a flag when you meet the x start criteria and set if off when you find the y end criteria. And of course to print out the lines when the flag is set.

So the pseudo-code could be something like this:

flag = false; while (there are lines in the file) { if (line equals "x") { flag = true; } elsif (line equals "y") { flag = false; } else { if (flag) { print line; } } }
There are many ways of translating this into actual Perl code, and there are shortcuts which could make the actual Perl code shorter, but there are also a few more things to be thought about in actual code, such as dealing with end-of-line characters, etc.

Please try to convert this pseudo-code into Perl and tell us where you're encountering problems.


In reply to Re: extract data from text file by Laurent_R
in thread extract data from text file by ikhan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.