Boy, does this look problematic! If there are newlines embedded in the records, then what is the record delimiter? Presumably, the answer is that when the specified pipe delimited fields have gone by, the next newline delimits the records; or more exactly, newlines within the message field are not record delimiters, but a newline outside of that field is a record delimiter. Because you don't seem to have control over the data that you are being fed, it looks like you are stuck with an extremely poorly formatted data set. This problem is actually only reducible if you promise that there won't be any pipes in the data. Promise? ;)

The first problem, then, is that the angle bracket operator (that is, <DATA> in your example) will break the file input on each newline by default, so you will be breaking the $line input on those newlines embedded in the message section of the text. To properly parse this, your best bet is probably to slurp the entire file in one fell swoop by temporarily doing undef $/ (the record delimiter variable set to undef reads to the end of the file). Then you will have to "manually" parse the file by looking for the first newline following five pipe characters to build the records. This is not a trivial task, mind you!

This is just intended as an overview of the method I would recommend. Given some time, I may work out a code implementation, or maybe some other monk will oblige before I get the chance.

-HZ

In reply to Re: newlines and sendmail by HyperZonk
in thread newlines and sendmail by hmbscully

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.