I've parsed data like this before, but I have a feeling that I am doing it isn't the most efficient.

I am setting flags for each section and then reading lines for that section until the flag changes.

Here is a sample of the data

It's RPSL data in case anyone is already familiar.

aut-num: AS19710 as-name: ASN descr: S4R admin-c: SNE1 tech-c: SNE1 import: from AS3356 63.215.71.1 at 63.215.71.2 action pref=20; +med=50; from AS3356 63.215.86.133 at 63.215.86.134 action pref= +50; med=150; accept ANY import: from AS3847 action pref=10; accept ANY export: to AS3847 announce AS19710 export: to AS3356 announce AS19710 notify: nwcontact@email mnt-by: S4R changed: andy@email 20010502 source: LEV

My problem is sections like import: and export: that span multiple lines without a section heading at the start of each line. Is there a standard method for handling something like this?

In reply to Best way to parse multiline data? by jalewis2

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.