The advice above about setting flags to track what sort of input you are currently examining and using those flags to drive what and how to write your output is on the mark and exactly how I approach this issue when writing www scraping tools. The only thing I want to add is a comment to your remark, that you "would like a solution where I don't have to use any modules or subroutines."

Modules and subroutines are how we re-use code. Code re-use is essential to writing testable code, minimizing bugs and copy-n-paste errors, expediting development and refactoring, avoid re-inventing wheels and leverage the work and wisdom of others to serve our own applications. Don't fear code re-use. It will make you a stronger developer.

-- Hugh

if( $lal && $lol ) { $life++; }

In reply to Re: parsing multiple lines by hesco
in thread parsing multiple lines by sm2004

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.