Great and wise perl monks. I seek wisdom.

I have a UNIX shell script on Sun/Solaris 10. In my script I ftp a file to the MVS mainframe (binary mode of course). There are several fields in each row of data in the file that need to be compressed into the MVS packed decimal (comp-3) format prior to ftp'ing the file to the mainframe dataset. I want to us a perl inline command (see below) in the UNIX shell script (if possible) in order to make those field conversions.

/usr/bin/perl -wpe 's/([0-9A-Za-z]{9})/pack("C",hex($1))/ge' < input_file > output_file

What I am wondering is: A. Is this even possible? B. If it is possible, is there a specific template to use in the pack function call (ie. I don't think "C" is the correct one etc.) in order to convert specific fields in each row of data to packed decimal (comp-3) format? (ie. the fields on MVS are PIC 9(7) COMP-3, or PIC 9(9) COMP-3 etc.)

Many kind thanks for your specific response regarding this specific solution. (I did read through the history logs but did not find a mention of this specific solution). jayw


In reply to ASCII text on UNIX (Sun/Solaris 10) to MVS packed decimal (comp-3) using perl pack inline command by jayw

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.