[Apologies for the broken return address in the previous message.]
From: Ranga Nathan <[EMAIL PROTECTED]>
Date: Fri, 15 Aug 2003 19:30:05 -0700
Guess I posed the question wrong. I needed to convert IBM's packed
decimals to an ascii string of numbers. Say in 4 byes I have a value
0x1234567C
I need to see this value as '1234567' , the last 0xC being a sign
indicator. I foud out that hex() can do this.
But hex is for parsing; you want to print it as "hex" so it can be
reinterpreted as decimal. How about something like this:
$result = substr(sprintf('%x', substr($data, $start, $len)), 0, -1)+0;
1. substr (or unpack) to extract the field;
2. sprintf '%x' to convert from PD to decimal digit string;
3. substr($field, 0, -1) to drop the sign; and finally
4. add zero to cause perl to drop leading zeros.
Sound worth a try?
This is a mess! I need to think through this. Firstly I need to know how
the mainframe converts these packed decimals into ascii.
I'm pretty sure I have my copy of "Principles of Operation" lying around
somewhere . . . but it's a good thing that we don't need it; hell might
freeze over before I find it. Fortunately, the worse that could happen
is that the mainframe stores the digits in a different order than you
expect, which only requires some experimentation with
split/reverse/join.
From: Dan Sugalski <[EMAIL PROTECTED]>
Date: Sat, 16 Aug 2003 12:55:31 -0400
At 7:30 PM -0700 8/15/03, Ranga Nathan wrote:
>However even before this is a problem. When I get the file from the
>mainframe, it has already been converted to ASCII but these hex values
>will be translated to some unintelligble characters.
If it's already gone through an ASCII->EBCDIC converter and the data
was in binary form, you're out of luck--the data has been corrupted.
The only way to be able to do this is to make sure that the fields in
question (if not the whole file) doesn't get converted.
As long as the conversion is reversible (i.e. doesn't map two EBCDIC
codes to the same ASCII code), you can recover the original, if you know
the mapping.
-- Bob
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm