Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

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


Description:

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!
  • 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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (11)
    As of 2015-07-03 10:40 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (51 votes), past polls