Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Keep It Simple, Stupid

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


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));
contributed by lhoward

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

@result = unpack "A16A20A20AA8",$input;


  • Please read these before you post! —
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • 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 cooling their heels in the Monastery: (7)
    As of 2013-12-21 02:34 GMT
    Find Nodes?
      Voting Booth?

      How do you parse XML?

      Results (436 votes), past polls