>>>>> "RN" == Ranga Nathan <[EMAIL PROTECTED]> writes:

  RN> Ok, I figured out that the best way to get a mainframe file containing 
  RN> packed decimals is to FTP it as binary and do the conversion in  Perl.
  RN> I know the record structure so I know where to expect the packed decimals 
  RN> (pd).

  RN> I find that all the bytes are reversed. Something to do with some
  RN> "Endian" ? (No, not me!)

again the unix utility dd can do al this for you and fast.

  RN> Think I am going somewhere with this. 

  RN> Now I have a pd in a variable called $digits. This is still in EBCDIC.

a quick search of cpan finds ebcdic convert modules and 5.8 has one in core.

  RN> I need to separate out the last 4 bits (used for signing the
  RN> field) and convert it to ascii (e.g 0xC should be 'C', 0xE should
  RN> be 'F') so I know what the sign was. Many of you know that the
  RN> last 4 bits are used for sign in a pd field and 'D' is -ve and
  RN> others +ive

i know the infamous sign nibble from IBM. i did plenty of work on packed
decimal stuff for pl1 compilers.

  RN> Convert all but the sign using hex() and sign it properly.

you have to get rid of the last nibble first. unpack can do that for
you. unpack the whole thing to an array, pop/shift off the sign nibble
(and keep it) and pack the rest back.

  RN> When I tried to rotate out the last 4 bits into a variable, I found the >> 
  RN> did not give me the expected value.  Nor does XOR, when I tried to read 
  RN> the sign (the last 4 bits).

you have to get that nibble in either integer or string mode and then do
the right thing with bitwise operators. bitwise stuff in perl5 is really
broken as it uses the last mode the value was in to decide to do string
or integer operations. p6 has the mode in the operator where it belongs.

i still don't have a full picture of the original format and the
destination format. using dd should save you a lot of work on the ibm
side. unpack/pack can convert nibbles to/from hex and then you can mung
the bytes.

uri

-- 
Uri Guttman  ------  [EMAIL PROTECTED]  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to