I've been using Perl in EDI for about 14 years, and I think it's the ideal tool. Other than a dedicated translator.

Your example does not seem to match your code. If the beginning record header is H01..., \nH00 will not find it. Our applications produce similarly formatted files:

H0010|... H0020|... H0040|... D0010|1|.. D0020|... D0030|... D0010|2|... D0020|... D0020|... D0030|...

I tend to use a state machine and read thru the records sequentially, rather than try to separate the data into blocks using regexes. YMMV.

EDI files typically are delimited, so you should look into Text::CSV which, despite the name, can use most any delimiter and not just commas. It helps a great deal when your delimiter may occur within the data itself. It will reliably divide your records into fields. So will split, but the module handles special cases you may not think of until they occur and mess up your process.

If your fields are fixed length, substr() will work just fine. You may also want to look into unpack(), but it can be unforgiving if your data does not match expectations. Either will let you easily divide a record into named variables, and $ordernumber will be much easier to understand than substr($H01record,32,30) when you revisit the program 6 months from now.

Dum Spiro Spero

In reply to Re: Simple but not elegant ? by GotToBTru
in thread Simple but not elegant ? by matthew_t_dooley

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.