Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

What is the best way to parse a 488 byte record?

by kfarr (Initiate)
on Jul 24, 2000 at 21:06 UTC ( #24125=categorized question: print w/replies, xml ) Need Help??
Contributed by kfarr on Jul 24, 2000 at 21:06 UTC
Q&A  > strings


I have a very ugly COBOL record descriptor, and need to parse the record into a semicolon delimted format. For this particular record type, the first two bytes comprise the first field, the next four, etc. etc. I suspect an array would make life easy, as I can assemble the final 'product' with a join command. Any ideas?

Answer: What is the best way to parse a 488 byte record?
contributed by fundflow

It sounds like all you need is this:

$out=join(";", unpack("A2A4...", $rec));
Answer: What is the best way to parse a 488 byte record?
contributed by lhoward

The best way is probably with unpack. See the Fixed-Length Fields Question discussion.

@result = unpack "A16A20A20AA8",$input;

Please (register and) log in if you wish to add an answer

  • 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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (2)
    As of 2021-02-25 02:51 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found