[Hartford-pm] sprintf sign handling question?
Bob Mariotti
r.mariotti at financialdatacorp.com
Tue Jun 22 21:54:49 CDT 2004
Fellow mongers;
I've been researching and playing with this issue all day. Sometimes
its time to ask those who know.
I have a perl program that extracts data from a report file. Some of
the fields (columns) are monetary with a trailing sign (i.e: 1,234.56-).
I extract the fields with the unpack function into scalars then strip
out the commas. If the field ends with a '-' char then I subtract the
scalar from zero placing it back into itself.
Next I create a string output record with the pack function and load the
fields with the sprintf function. Finally I write the formatted string
to a file. Simple, huh?
OK - I am getting what looks like a properly formatted file. However, I
am having problems with sign handling. Can anyone please offer
suggestions to help me arrive at the following:
input field: 1,234.56-
getting output: -00123456
Desired output: 00123456-
or preferably: x'30303132333435d6' which is a zoned ascii decimal field
with a negating overstrike on the low order byte.
Suggestions please?
Thanks all.
Bob
Hartford PM
More information about the Hartford-pm
mailing list